Skip to content
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

Feature Request: Function-Calls as requirements #1263

Open
Species8372 opened this issue Aug 10, 2018 · 1 comment
Open

Feature Request: Function-Calls as requirements #1263

Species8372 opened this issue Aug 10, 2018 · 1 comment

Comments

@Species8372
Copy link

Consider one Field with a validator has to consider another field as requirement. E.g. the second date-field must be larger than the first.

Currently we would access the other field from inside our own custom validator.

It would be nice to have the possibility to write the following to allow for a more generic custom validator approach:

<input id="a" data-parsley-mindate="$('#B').val()" .../>

The validator then would receive the evaluated funtion-call == the current value of the other field (or any other result of the referenced function as requirement.

Currently we did a workaround like

window.Parsley.addValidator (maxdateValidatorname, {
	requirementType: 'string',
	validateString: function (value, requirement, parsleyfield) {
		if(typeof window[requirement.substr(0,requirement.indexOf('('))] === "function") 
                 requirement = eval(requirement);
                //.....validate

}});
 

If i accidentally missed the fact that such a thing can be done already more easily i'd like to hear about it :)

@marcandre
Copy link
Collaborator

It's indeed not as easy as it should be.

This example shows one way to do it.
Please check #949 for future development...

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

No branches or pull requests

2 participants