mercredi 2 juin 2021

Uncheck all checkboxes - i have a bug

I have a component in VUE3 and within it, a watch function which, I hope will un-select a complete list of checkboxes.

This happens correctly. But when you click again on any checkbox, the one you have touched is activated, and also all those that have been deactivated by the "watch" function are activated.

This is my input list:

  <div v-for="c of caracteristicas" :key="c.id">
      <input
        type="checkbox"
        :id="c.id"
        :value="c.id"
        v-model="caracteristicasSeleccionadas"
      />
     
      <label :for="c.id"></label>
    </div>

this is my watchfunction

 watch(stateSeleccionado, () => {
      if (stateSeleccionado.value.length > 0) {
        store.dispatch(
          "filtrosSeleccionados/addFiltrosSeleccionadosAction",
          data.value
        );
      } else {
        root.value.children.forEach((e) => {
          if (e.children[0] !== undefined) {
            e.children[0].checked = false;
          }
        });
        store.dispatch(
          "filtrosSeleccionados/removeFiltrosSeleccionadosAction",
          data.value
        );
      }
    });

I think that i have some trouble in

 if (e.children[0] !== undefined) {
            e.children[0].checked = false;
          }

Someone can helpme please? thanks a lot




Aucun commentaire:

Enregistrer un commentaire