I have one field that's not bind to any form element, but I would like to add required validation to it like I have for any other fields that are bind to some controls. I tried to use
<input type="hidden" name="requiredField" ng-model="vm.requiredField" required />
but while field was marked as $invalid and the whole form was still $valid.
Do you have any idea how to make such validation?
Eventually it looks like it should works. The reason why it doesn't work for me is because there was hidden code that changed $invalid field manually. I found it by using such script: https://github.com/paulirish/break-on-access
Related
I am trying ng-required for the first time and it is solving my problem of validations. I just need to know how can I provide my custom messages with validations provided by ng-required. The fields on which ng-required is applied are dynamically generated with ng-repeat. So the custom messaged need to contain the field name.
i am using angularjs' form stuff to gather user information. to get time i user <timpicker> it seems that this field is not set (ng-model of timepicker is null) if i call my ng-submit="submit()".
The only way i found so far is to call ng-change in timepicker and set a viable in scope which is then used in submit. Beside the fact that this is ugly, the main problem is if the user doesn't change the value (default is now) i don't have a time.
Is there a way to gather all ng-model variables in $scope on form's "ng-submit"?
EDIT It is not a problem of form its problem of timepicker. As soon as i change the time once the model gets filled (without the need of change method)
It will gather all ng-model variables on $scope that are set on input fields within the form. If you want to add a variable to your form without actually showing it on the screen, you can do:
<input type="hidden" ng-model="yourVariable" />
I have a form where certain inputs have "required" attribute. I also have a button that adds form fields when clicked, but it always triggers the form validation message when the required fields are not filled out. I only want form validation to trigger for ng-submit and not ng-click. Is this possible?
If you have a look at the W3C specification, it would seem like the obvious thing to try is to mark your button elements with type='button' when you don't want them to submit.
The thing to note in particular is where it says
A button element with no type attribute specified represents the same thing as a button element with its type attribute set to "submit"
when you do not want submission on specific button then define type="button". it will 100% work
Use novalidate for your form:
<form name="aForm" novalidate>
or use ng-form instead:
<div ng-form name="aForm">
Check this link for further info about form validation in AngularJS.
Angular has ng-focus to attach to a form-field to tell if it has focus.
But as I understand I cannot use ng-focus on the <form> itself. What would be the simplest way to tell if any field in a form has focus but without attaching ng-focus on each and every field? Say I have a large form with many fields, and I do want check each field...
I would like to use the angular x-editable directive to work with a text field per the following
(a) I don't want to display buttons. I tried the buttons=no option but it does not seem to work with input of type text.
See the fiddle here.
(b) I want the underlying ng-model property to update immediately with each keystroke , without waiting for the user to focus out of the input. (as is default behavior with vanilla angular, eg. <input type=text ng-model="somepropertyname" />
How can one achieve (a) and (b) with angular x-editable? link to fiddle
Answer to 1(a) is to add the blur="submit" attribute (in addition to buttons="no")