Access HTML form input value if ng-model is invalid - angularjs

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?

Related

How to check if an input element has an error(s) using 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.

How to allow 2 decimal separators with Material UI?

I use Material UI in my project and I would like to allow the user to choose between comma or period as decimal separator. They are not currency input fields, but just numerical fields that can have decimal places. Currently only period is accepted, if the user presses comma instead nothing happens.
Making its type='number' will restrict the value parsing logic to the default one added in the html. if we want to parse the value entered in the field by our rules, we have to parse it explicitly. For that purpose we can use a regex to test the input value coming on on each keystroke on the field. and then will restrict populating the value if it restricts the rule.
You can use a following Regex to test for the input
//Dot: /^\d+(\.\d{0,2})?$/
//Comma: /^\d+(,\d{0,2})?$/
You see the running demo here: https://codesandbox.io/s/material-demo-forked-2gmmn?file=/demo.js

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.

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.

Accessing form elements filling fields?

I have a form which has an initial element, I am running a check using the confidence feature to check for other phrases that might match the user's input. If there are then i am going to a menu, from here i am asking the user to input a dtmf value to say whether one of these values where correct. If the user selects an option, i want it to fill that field of which it checked, with that interpretation or possibly go to another form which does the same thing, if i choose to do it using the other form, can u access filled fields from another form?
regards
According to the VoiceXML Specification the scope for that type of variable would only be accessible in the form. But you can assign the values to another variable before leaving the form that has document scope (i.e. defined just below the vxml tag). Or even give it global scope by defining the variable in the root document, which makes it accessible to the whole application.

Resources