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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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?


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x