formly-js / angular-formly

JavaScript powered forms for AngularJS
http://docs.angular-formly.com
MIT License
2.23k stars 405 forks source link

Adding validator to non-required field makes empty field invalid #623

Closed luckyagarwal3247 closed 8 years ago

luckyagarwal3247 commented 8 years ago

I want to have a field in my form which is not required and can be left blank but if provided must be valid when compared to a predefined regex. I have added a validator to this field and the validator works fine when some string is input in the field.

The problem arises when user clicks on the field but clicks out without adding any text. In this case the field becomes invalid which is incorrect since it is not required.

kentcdodds commented 8 years ago

You're validator needs to check for empty and return valid if it's empty. The examples on the website do this. Thanks!