How to add validation without making field required?
Opened this issue · 21 comments
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
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.
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?
Hello @RajatJain4061
are you working on this fix?
@RajatJain4061, I also need this fixed. Can you fix it?
@josueruiz7 @felipe-azevedo I will fix this ASAP within next 2 days
@RajatJain4061 any news on this?
@RajatJain4061 hey, man. Sorry to bother again, but I really need this.
@RajatJain4061 any news? thanks.
You can fix that by checking value is empty (return true) in the validate func in RegexRule
@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.
@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.
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.
@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
@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 hi, any news on this?
Thanks.
@RajatJain4061 can you fix this please?
@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.
Any news for this issue? I also need the fix.
Thanks.