I have an issue with my AngularJS
checkbox where they become undefined
when they are unchecked. Can't figure out why this is happening.
<input type="checkbox" name="available" ng-model="formData.available" ng-true-value="1" ng-false-value="0" required>
With the above code; default on page load is 0
. when Its checked it becomes 1
. When I uncheck it it becomes undefined
Any help appreciated.
Thanks to the comments I've realised that the required
option is not necessary and was the cause of the issue. Thanks guys!
If you need the required attribute set ng-model-options="{ allowInvalid: true }" so undefined becomes false on the model.
https://docs.angularjs.org/api/ng/directive/ngModelOptions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With