Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
130
rated 0 times [  135] [ 5]  / answers: 1 / hits: 26615  / 11 Years ago, thu, august 15, 2013, 12:00:00

Given a simple html form like this:



<form name=myForm action=#sent method=post ng-app>
<input name=userPreference1 type=text ng-model=shipment.userPreference />
<input name=userPreference1 type=text ng-model=shipment.userPreference />
<input name=userPreference1 type=text ng-model=shipment.userPreference />
... submit input and all the other code...
</form>


I need your help to know how to check on validation time, if at least one of the inputs is empty. The desired validation is the following. The user must complete at least one a preference.



Using jQuery this:



if ( $(input).val() ==  ) {


Works ok, but would like to figure out how to do the same thing using angular.



Thanks so much in advance,



Guillermo


More From » html

 Answers
3

So the idea is to disable the submit button if all inputs are blank. You can do like this



<form name=myForm action=#sent method=post ng-app>
<input name=userPreference1 type=text ng-model=shipment.userPreference1 />
<input name=userPreference1 type=text ng-model=shipment.userPreference2 />
<input name=userPreference1 type=text ng-model=shipment.userPreference3 />

<button type=submit ng-disabled=!(!!shipment.userPreference1 || !!shipment.userPreference2 || !!shipment.userPreference3)>Submit</button>
</form>


!!str is to force to convert str to a boolean value. And both !!null and !! are evaluated to be false.



Demo


[#76333] Wednesday, August 14, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
claudia

Total Points: 734
Total Questions: 106
Total Answers: 113

Location: Sweden
Member since Fri, Apr 16, 2021
3 Years ago
;