I'm using ng messages module for my validation purpose, I have two input fields. I need to check whether both the input boxes have 0 as its value. It should not allow user to save form, if both the input fields have 0.
How can I achieve this using ng-messages module?
<input class="form-control" type="text" name="text1" ng-model="text1">
<input class="form-control" type="text" name="text2" ng-model="text2">
What I need is, invalidate the form if both of these text boxes have value as 0 at the same time.
Related
I am completely new to AngularJs. I need to make autocomplete=off for a password input.
Is autocomplete=off the only way or do we have to do it in some different way in AngularJs?
This doesn't nothing to do with AngularJS at all, but simply html.
Regarding to your statement, password fields shouldn't be autocompleting if they are set to type password, otherwise if you want to set a specific field inside a form to autocomplete off you can do it setting that property to false like this <input autocomplete="on|off">.
This can be defined at form level or at input level. In a form it would be like this:
<form action="" autocomplete="on|off">
</form>
Also you can define it in a form level, and override the behavior for some specific inputs like this:
<form action="" name="myform" autocomplete="on">
<input autocomplete="off" name="myInput" >
</form>
In the above code, in the form myform the autocomplete is on, it means all inputs (the one which allow it) will do autocomplete, but in the input myInput will not, since it overrides the form behavior.
More info can be found in The HTML autocomplete attribute
This should be sufficient:
<input type="password"
autocomplete="off"
placeholder="password"
ng-model="vc.password">
I added the autocomplete="off" just for redundancy but it seems completely unnecessary.
jsbin - https://jsbin.com/bowuxopese/edit?html,js,output
I have a form text field it is required but its initial value is an empty string, so when I load the form the controller validates the form field and marks it as error, I want on the initial load not to validate the form field only after an onblur event.
<input data-ng-model="MyCtrl.opportunity.company" type="text" class="form-control" name="company" ng-model-options="{ updateOn: 'blur' }" required />
And here is the fiddle http://jsfiddle.net/petran/Lvc0u55v/725/
I know I can call $setValidity on controller I am looking for a more elegant solution if there is exist.
Add this statement to ng-class statement:
...&& addOpportunityForm.company.$dirty...
Use the $pristine for validation tool in AngularJS. This will allow the funtion to wait until the input field has been changed before testing the condition. You can learn more about form states here: Angular Form States
I create an AngularJS App without < form >. But there is input field.
One of my input field is number.
<input type="number" class="input numberfield" placeholder="0" ng-change="changePrice()" ng-model="price" ng-pattern="/^(\d)+$/" name="price" required />
Now how I show the error message without from name?
<input type="number" class="input numberfield" placeholder="0" ng-change="changePrice()" ng-model="price" ng-pattern="/^(\d)+$/" name="price" required />
<span class="red" ng-show="price.$error.pattern">The price must be given in number format!</span>
When I type some any character inside the field, it show ng-invalid ng-invalid-number tag in input class (screenshot 1). When type some number it's show ng-valid class (screenshot 2). So my code is works.
But problem is that my error message does not work.
I follow this tutorial: http://codepen.io/astockwell/pen/JyCva
But I don't have form tag
screenshot 1 - ng-invalid-number
screenshot 2 - ng-valid-number
Any idea?
Add a form tag.
Angular's validations only work when you have a form tag. You already know your problem is that you don't have a form tag, so add one.
If you can't add a form tag (like there's already some parent form tag somewhere), use ng-form instead, since you can nest those.
I have a situation where I need to escape the following string to be used as the preloaded value for an input field. I would usually use data-bind-html but this doesn't show in the input box.
Here is my string:
"Website Design & Development"
and currently my input field is as follows:
<input class="form-control" type="text" ng-model="group.name" required>
When I use mg-model, it populates the input form value fine, but when I use the following:
<input class="form-control" type="text" ng-bind-html="group.name" required>
Am I doing this correctly or can someone see where I am going wrong? I would ideally like a way to escape the html entities in the controller before it gets shown in the view but I am not sure if this is possible?
Thanks
I have parsleyjs and jquery on my page and I'm trying to get parsley to work when the user clicks out of the input field. I have marked it as a required field and also set it to trigger if its blank or empty when the user clicks out of the input field. But right now its not showing any error. What am I doing wrong.
<form action="" method="post" class="form-horizontal" data-validate="parsley">
<input type="text" name="firstname" data-required="true" data-trigger="blur" data-notblank="true" placeholder="First Name" />
</form>
Second question is there a way to trigger a custom validation method in another js file for specific input fields? If so how would I go about it in this setup.
By default parsley only validates once there are 3 or more characters in a field.
If you want to validate on blur for empty, then you need
'data-validation-minlength' => 0 as an attribute