I'm facing a challenge with radio buttons in my form. While checkboxes could easily solve this issue, the customer specifically requested radio buttons.
Here is the relevant section of the form:
<label>
<span>I Agree*</span>
<input type="radio" name="privacy_1" value="1" ng-model="ctrl.utente.privacy_1" ng-required="!ctrl.isValidPrivacy()"/>
</label>
<label>
<span>I Disagree</span>
<input type="radio" name="privacy_1" value="0" ng-model="ctrl.utente.privacy_1"/>
</label>
Accompanied by the corresponding JS code:
self.isValidPrivacy = function () {
return (!self.utente.privacy_1 || self.utente.privacy_1 == 0) ? false : true;
};
and the condition ctrl.utente.privacy_1
needs to be equal to 1
.
Despite attempts like
ng-required="ctrl.utente.privacy_1 != 1"
or
ng-required="!ctrl.utente.privacy_1
(by removing value="0"
from the second radio input), I have yet to find a solution.
The validation error for ctrl.utente.privacy_1 == 0
does not appear, and it cannot be selected as the default option (ctrl.utente.privacy_1
cannot be false
by default).
None of the answers on StackOverflow have successfully resolved my issue so far.