Element: [Feature Request] Pass options to validator

Created on 30 May 2017  ·  3Comments  ·  Source: ElemeFE/element

Existing Component

Yes

Component Name

Form

Description

It would be nice and very useful to pass options to validator.

For example i have rule requiredIf and i would like to pass options to this rule.

I see async-validator supports options but i have no idea how to use this.

If its possible maybe update documentations that it would be easyer to read.

Most helpful comment

I meant when i create custom validator then i would like to add options to it.

But i just added additional field and i can access it from first parameter so we can call it solved :)

I don't have example to give right now cause im on the move.
But it wen something like that

I add rule like that:
{ validator: customvalidator, options:[bla,foo,bar], trigger: 'blur' }

And then i can access it like that

const customvalidator = (rule, value, callback) => {
  const options = rule.options.split(',');
  // Now i got array of options. 
};

All 3 comments

Sorry...I can not get your point, what's the "option" slove?

I meant when i create custom validator then i would like to add options to it.

But i just added additional field and i can access it from first parameter so we can call it solved :)

I don't have example to give right now cause im on the move.
But it wen something like that

I add rule like that:
{ validator: customvalidator, options:[bla,foo,bar], trigger: 'blur' }

And then i can access it like that

const customvalidator = (rule, value, callback) => {
  const options = rule.options.split(',');
  // Now i got array of options. 
};

I just want to comment for anyone that stumbles upon this, this appears to be implemented.

It would be nice if this was in the documentation though, since I had no idea I could pass more parameters into the validator.

Was this page helpful?
0 / 5 - 0 ratings