简体   繁体   中英

angular form validation not working as expected

I'm trying to keep a button disabled under two conditions. The first is if a required fields condition has been meet (is there isn't text in the input) the second is if the Boolean value is false. The problem is for some reason my directive seems to acting like an or rather than an And where the button becomes enabled after either one of the two conditions is meet.

Here is the button I'm trying to keep disabled when both conditions aren't met

<button type="button" id ='submission' class="btn btn-success ng-hide" ng-show="submissionReady" ng-hide="afterSubmission" ng-click="saveScenario()" ng-disabled="myForm.title.$invalid && !playerService.status">Save Scenario</button>

You want the button to be disabled if one of the conditions is true. Not if both conditions are true. So you need an OR, not an AND:

ng-disabled="myForm.title.$invalid || !playerService.status"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM