Reputation: 3137
I'm fighting with angular input checkboxes. I have a simple input that looks like this...
<input type="checkbox" ng-model="selectedExercise.isTimed" required/>
However, when I uncheck the box it removes the .isTimed field from my object, when I want to set it equal to false. For example...
checked
{
"name": "Work",
"isTimed": true,
"duration": 3,
}
unchecked
{
"name": "Work",
"duration": 3,
}
I have hacked this to work by adding an ng-change function, but it is super hack in that it just checks to see if angular removed the field, then re-adds it. Is there a proper way to setup my input checkbox so angular won't remove the object field when the box is unchecked?
Upvotes: 0
Views: 1061
Reputation: 36
I had same problem. You can solve it just by deleting "required" in checkbox. As I understand it's just
Upvotes: 1
Reputation: 3
This might have to do with the way that checkboxes are processed. They tend to only return a value when they are true. However, with angular you can override this and capture either state.
<input type="checkbox" ng-model="selectedExercise.isTimed" ng-true-value="yep" ng-false-value="nope" required/>
Upvotes: 0