Skip to content

Question - Injecting custom validation on form fields #601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kazoompa opened this issue Nov 21, 2015 · 4 comments
Closed

Question - Injecting custom validation on form fields #601

kazoompa opened this issue Nov 21, 2015 · 4 comments

Comments

@kazoompa
Copy link

Hi,

I have been Google-ing a lot on this and I couldn't find any descent answer, here is our setup:

The form schema and definition are returned from our Java server to our Angular client as a JSON document. We would like to add a custom validator on a form field. Since the form definition is returned as a string JSON, we cannot have the $validators set on the field as described in the documentation. We need to parse the form definition, find the valid field and then add our custom validator on the fields $validators list. Is there any way to do this nicely?

Thanks.

@Knuckles9090
Copy link

I used the onChange attribute to send the value of the input to a custom validator function. For example
"onChange": "validateSSN(modelValue, form)". Then in this function you could broadcast an schemaerror, if the value does not match a pattern or whatever criteria you need it to pass.

@kazoompa
Copy link
Author

Thanks for the suggestion but the rendered form is client dependent and most of the users are researches who know nothing about programming. My idea is along the line of having a registry of validators per client and have a mechanism of identifying the field at parse time to inject the validator and let angular & schema-form take care of the rest.

Right now I am playing with the JSON.parse(json, reviver). I thought the reviver can provide me the name of the field which can be the key to my registry. Once a validator is found, through the reviver I can change the parse JSON node and inject the validator.

Cheers and waiting for some juicy solution ;)

@Anthropic
Copy link
Member

@kazoompa can you add validators to tv4 or via a directive by modifying the decorator templates?

@Anthropic
Copy link
Member

Closing due to lack of recent comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants