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

How to call Multiple function from Validator field?? #2

Open
Shraddha80011 opened this issue Nov 2, 2017 · 3 comments
Open

How to call Multiple function from Validator field?? #2

Shraddha80011 opened this issue Nov 2, 2017 · 3 comments

Comments

@Shraddha80011
Copy link

Shraddha80011 commented Nov 2, 2017

I want to call more than one function in validator from complex schema,
my code like this

var fieldValidatorFunc =  function( obj, value, fieldName ){
 alert("fieldValidatorFunc")
}; 
var ABCValidatorFunc =  function( obj, value, fieldName ){
  alert("ABCValidatorFunc")
};
complexSchema = new Schema({
  age: {
    type: 'number',
    default: 15,
    min: 0,
    max: 130,
    validator: fieldValidatorFunc, ABCValidatorFunc, extraParameter: true 
  }
});

But it is only called fieldValidatorFunc, it doesn't call ABCValidatorFunc.
I want to call both function at a time OR one by one.
Thanks.

@mercmobily
Copy link
Collaborator

Hi,

Are you sure you wrote the code correctly?
When you say:

validator: fieldValidatorFunc, ABCValidatorFunc, extraParameter: true

It doesn't strike me as valid Javascript code, quite frankly.
Running it with Chrome, it ends up only assigning fieldValidatorFunc to validator.

Maybe a possible syntax would be:

validator: [ fieldValidatorFunc, ABCValidatorFunc ]

Is that something you'd like to see?

I wrote this code to support JsonRestStores. However, I will be happy to improve it.

Merc.

@Shraddha80011
Copy link
Author

Yes, I know that my code is not correct, but I want to show you How to call two function in validator field??
And you suggest me a way to call functions but it is also not working it shows me error like this,
Validator function needs to be a function, found: object.
Then now please give me another way to call more than one function in Validator field.
Thanks

@mercmobily
Copy link
Collaborator

Sorry to ask you, but... would you be able to provide a real-life use case for this need?
In general, the best thing to do is to use one validator, which will then apply several checks. These checks can and should be implemented in other functions, so that you can "include" any check you like...

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