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 add validation without making field required? #185

Open
emadd opened this issue Jun 21, 2017 · 21 comments
Open

How to add validation without making field required? #185

emadd opened this issue Jun 21, 2017 · 21 comments
Assignees

Comments

@emadd
Copy link

emadd commented Jun 21, 2017

It seems it's not possible to set a validation rule on a field without making it required. i.e. - Phone number should not be required but if something is entered, validate it

@RajatJain4061
Copy link
Member

Absolutely right, If the field is empty then it tries to validate the value. There should be a condition to check if the field does not contains RequiredRule then do not validate field with blank values.

@davepatterson davepatterson self-assigned this Jul 16, 2017
@michzio
Copy link

michzio commented Feb 27, 2018

Yes this seems to be issue I have empty fields without RequiredRule throwing errors so I think now there is only possibility to check by type of errors?

@RajatJain4061 RajatJain4061 self-assigned this Jun 13, 2018
@josueruiz7
Copy link

Hello @RajatJain4061
are you working on this fix?

@felipe-azevedo
Copy link

@RajatJain4061, I also need this fixed. Can you fix it?

@RajatJain4061
Copy link
Member

@josueruiz7 @felipe-azevedo I will fix this ASAP within next 2 days

@felipe-azevedo
Copy link

@RajatJain4061 any news on this?

@felipe-azevedo
Copy link

@RajatJain4061 hey, man. Sorry to bother again, but I really need this.

@josueruiz7
Copy link

@RajatJain4061 any news? thanks.

@phuongnguyen2359
Copy link

phuongnguyen2359 commented Aug 17, 2018

You can fix that by checking value is empty (return true) in the validate func in RegexRule

@felipe-azevedo
Copy link

@phuongnguyen2359 I expected the framework to do this. I have too many fields and I don't want to check each one for a value before validating.
@RajatJain4061 what happened to the fix? I need this, man. Thanks.

@felipe-azevedo
Copy link

@phuongnguyen2359 Also, this affects every Rule, not just Regex.
For example if I have minLength and maxLength validations and the field is not required, empty would be an acceptable value, but it's not because it will violate the minLength.

@RajatJain4061
Copy link
Member

RajatJain4061 commented Aug 17, 2018 via email

@felipe-azevedo
Copy link

Thanks, @RajatJain4061
If you want a suggestion, I'd add a property to the Validator's init to allow empty for non-required fields. If that's set to true, when you validate a field that's not required and it's empty, all validations should return true, i.e. all rules should be ignored.

@RajatJain4061
Copy link
Member

RajatJain4061 commented Aug 17, 2018 via email

@phuongnguyen2359
Copy link

@felipe-azevedo if the framework do this. it's cool still wait for it. In my case, I just need email field can be empty so doing this just affects email rule

@felipe-azevedo
Copy link

@phuongnguyen2359 I have big forms, 15, 20 fields all with validations. Most of the fields are required, but some are not, and to avoid having to create an exception for each of the affected rules, I wanted to fix this across the board.
@RajatJain4061 this was my suggestion for you to fix it, man. I don't have time to fix it.

@RajatJain4061
Copy link
Member

RajatJain4061 commented Aug 17, 2018 via email

@felipe-azevedo
Copy link

@RajatJain4061 hi, any news on this?
Thanks.

@felipe-azevedo
Copy link

@RajatJain4061 can you fix this please?

@felipe-azevedo
Copy link

@RajatJain4061, @davepatterson
is this issue ever going to be fixed?
This is an important issue and I'd really appreciate if it was fixed.
It's been open for a very long time.
Thank you.

@josueruiz7
Copy link

Any news for this issue? I also need the fix.

Thanks.

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

7 participants