0
I am trying to create an object containing all the inputs of a form so that if any are checked, others become disable. Is there any way
document.forms['formParada'].elements['checkboxTipoParada'];
This is the HTML
<label for="tipoParada">Tipo de parada:</label><br>
<form id="formParada" name="tipoParada">
<input type="checkbox" name="checkboxTipoParada" ng-click="defineParada()">Disponibilidade<br>
<input type="checkbox" name="checkboxTipoParada" ng-click="defineParada()">Performance<br>
<input type="checkbox" name="checkboxTipoParada" ng-click="defineParada()">Qualidade<br>
</form>
And so is my code
$scope.defineParada = function () {
let checkboxObj = angular.element("formParada").elements;
for (let i = 0; i < checkboxObj.length; i++){
if (checkboxObj[i].checked == true){
console.log(checkboxObj[i].value);
} else {
checkboxObj[i].disabled = true;
}
}
};
Doing this with angular is out of the standard and it doesn’t even make sense to use it like this, it also loses reactivity. Use ng-model and do the manipulation for it. Depending on how you want to trigger the modifications you can use ng-click, ng-change or a $watch.
– Leonardo Getulio