Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remote attribute doesn't trigger when field is blank

I'm using RemoteAttribute for a particular field on my form. The purpose of it is not important. What is important is that it needs to fire the validation action whenever the field is changed. This is working fine for me except when the field is changed to be blank.

I've Googled this but found no results. Does anybody know if RemoteAttribute does actually trigger for blank fields and if not, how it can be forced?

Alternatively, can the remote validator be customised/modified to trigger for blank values?

like image 303
Paul Fleming Avatar asked Feb 05 '13 12:02

Paul Fleming


1 Answers

jQuery validation will not run any rules if the value of an element is empty. If you have a minLength = 2 rule but the input field is left empty the rule will not fail. Only if the user enters 1 character it will fail.

The same idea applies to a remote validator. If the value is empty then it does not go to the server.

I don't think there is an option in the plugin to change this behavior. You will need to create a custom async rule to get the behavior you are expecting. This might turn a little tricky. Are you sure there is no other way of doing it? Does it make sense to validate an empty string in the server? Can you add the required rule?

like image 100
epignosisx Avatar answered Oct 10 '22 17:10

epignosisx