react-validation icon indicating copy to clipboard operation
react-validation copied to clipboard

Validation with external parameters

Open SergeyNedayvoda opened this issue 9 years ago • 5 comments

How to implement validation with external parameters (w/o rules hardcoding, like lt8)? (e.g. minLength, maxLength)

SergeyNedayvoda avatar Nov 08 '16 16:11 SergeyNedayvoda

Hey @SergeyNedayvoda ,

What's the purpose of that? Could you just define that rule like lt8?

Thanks, Oleksii

Lesha-spr avatar Nov 09 '16 08:11 Lesha-spr

Hi @Lesha-spr , Thanks for the answer

I will describe the situation We have a lot fields with different length rules (e.g. 1st field: 10-20 symbols, 2nd: 15-25, 3rd: 15-35, n:X-Y symbols) We don't want to define separate rules for each case. Ideally we should be able to pass parameters from component to the validator (maybe like validations={['alpha', 'minLength:10', 'maxLength:20']}) Or maybe we should pass component to the rule/hint function (currently we pass only (value, components)), so we'll be able to get the dynamic parameters for validation from the component attributes e.g. <Validation.components.Input type='text' value='' minLength='10' maxLength='20' validations={['alpha', 'minLength', 'maxLength']}/>

+this functionality will be useful if we want to define a different error messages for an one rule I can provide a lot of scenarios when access to the component attributes or dynamic parameters would be useful

Thanks

SergeyNedayvoda avatar Nov 09 '16 10:11 SergeyNedayvoda

Hi @Lesha-spr ,

are there any news about this issue?

Thanks

thecyrusdh avatar Feb 10 '17 14:02 thecyrusdh

@SergeyNedayvoda Did you find a solution, or can you recommend a library which handles the dynamic nature of forms and fields?

melchoir55 avatar Mar 31 '17 07:03 melchoir55

@melchoir55 we use formsy-react and formsy-material-ui components

SergeyNedayvoda avatar Mar 31 '17 09:03 SergeyNedayvoda