How to check if an input element has an error(s) using Parsley.js? - parsley.js

After adding custom errors to input fields using Parsley's inputField.addError(...) method, is there a way to do something like a inputField.hasError() to check if the input field has any manually added errors? Right now, after manually adding an error(s) to an input field, if all the constraints defined on the field using data-parsley-* attributes are valid, the field is marked as valid. I want the field to be marked invalid as long as the manually added errors are present.

Related

Codename One - Validate only one input at a time

A problem of the Validator class is that it validates all the inputs to which a constraint is added (that means that an error message is shown in not already filled inputs or selected pickers):
Validator val = new Validator();
val.addConstraint(title, new LengthConstraint(2));
val.addConstraint(price, new NumericConstraint(true));
In this example, the validator will show an error for both title and price even if the user didn't entered a price yet.
It would be more intuitive that an error is shown only after the user has given the input, that means to show an error for the price only after that a price is given.
I didn't find a code to implement this behavior.
My first thought was just create a validator which will check if something was modified and add it to the validation chain. However, that would mean the input could be valid if you didn't enter everything.
This is a feature that should be implemented in the rendering logic for this class. In Validator itself. You can file an RFE for that or just implement it in a pull request.

Redux form set custom error message based on field's hinttext in Field Validation

I am trying to write a Field validation so that i don't have to write separate validation in every file. While trying to do it, i am able to get value of the field as well as the whole form fields.
I have to set the error message based on the field name, eg.
For field name as Firstname the error message has to be : First name is invalid.
is there a way to implement this with the Field Validation, or the sync validation is the only way?
Any help will be appreciated.
There is a "hacky" way to do this. Since in field validation you get field value and form values as parameters, you could get field name (which would be the key of the form values object) by searching for a matching value in form values. Then you would need to have a file with field name translations where you could get the field name, e.g. translations[fieldName].
However, since the above way requires more setup and sync validation is relatively simple, I would recommend using sync validation.

Updating the min/max templateOptions

Please have a look at the following jsbin
At first, numberTest requires the user to input a number between 5 and 10 (as noted by the description beneath it). If you press the change min/max button, the min/max fields are updated to 500 and 510. Again, you can see the description has updated to these new values.
However, it still requires the user to enter a value between the original min/max settings (5 and 10). How do I get the validation to see the new settings? Clearly, I am setting them correctly because the description under the field is updating correctly. It seems that the validation is stuck with the original values.
EDIT: I added better validation messages to the field. You can see that even the validation message thinks that the new min/max values are correct but the field still requires 5-10.
The problem is that you're not using expressionProperties to change the values, but changing them manually. angular-formly does a lot of optimizations to make sure we're not adding watchers that are unnecessary. expressionProperties is how you inform angular-formly that these values can change.
Here you go: http://jsbin.com/xenuqo/edit?js,output
For more on expressionProperties see this

Show and hide server-side errors in AngularJS 1.3+ forms

I'm using the Angular framework with Angular Material controls in my recent application. I'm looking for a good solution for the following problem:
A form form with an input field named nickname is shown to the user. After the user has chosen a nickname and submitted the form, the server checks whether the nickname has already been taken. In that case, it returns an error to the Angular client.
To show an appropriate error to the user, the code then calls form.nickname.$setValidity('nicknameTaken', true). The new ngMessages module is used to display the error to the user. Further form.$isInvalid is used to disable the form controls to prevent the user from resubmitting the invalid nickname.
My problem is now the following: I'd like to have the error nicknameTaken automatically being removed as soon as the user begins to edit the form fields again. What is a good way to do this? Is there a predefined route to go when it comes to server-side validation errors of this kind? (Note that I am not asking for asynchronous validation because I only want to contact my server when the form is actually being submitted.)
I would write a normal validator directive instead. Something like
<input blacklist="takenNickNames" .../>
This directive would simply add a validator to the input, and this validator would make the input invalid if the model value is contained inside the given takenNickNames array (and valid if it's not present).
The takenNickNames array would be empty initially. When the form is submitted and the error comes back, the controller would add the invalid nick name to the array.
So, every time the user would enter something, the validator would be triggered, and would set the field valid or not, based on the taken nicknames stored in the array.
Here is a working example.

Access HTML form input value if ng-model is invalid

Suppose I have form with one input and validation rules like min-length, max-length, etc. I want to show hint to user how much symbols he should append to (or remove from) current input value to pass validation rules. But ng-model that corresponds to this input is empty because input is invalid. How can I access current input value?

Resources