HenrikJoreteg / Happy.js

$('form').isHappy() – Lightweight, extensible form validation plugin for jQuery/Zepto.js
http://projects.joreteg.com/Happy.js/
MIT License
412 stars 123 forks source link

Partial selectors? #42

Closed pepefloyd closed 10 years ago

pepefloyd commented 10 years ago

I am not sure if this is a bug or something I am doing wrong but Happy doesn't seem to work with partial selectors.

Syntax error, unrecognized expression: '[id$=casecreate-subject-input]'

I also tried using the class selector but even though it doesn't produce an error it ignores the validation

fields: {
'.subject': { required: true, message: 'hey' }

wraithgar commented 10 years ago

One of the assumptions happy.js makes is that your selector is either a simple class or id. When it adds the error message it tries to attach an id of whatever the selector was plus "_unhappy". It does this by shaving off the first character of the selector (since it's assumed to be either . or #).

Because of this when it tries to set the id of the error div you get a Syntax error, for instance Uncaught Syntax error, unrecognized expression: class='*Name']_unhappy.

Selectors right now in happy.js need to be either ids or class names. I don't know why the second example you gave '.subject' didn't work, I was able to change the id yourName to the class yourName in demo.html and everything worked fine for me. Can you provide more info on what you're trying to do there?

pepefloyd commented 10 years ago

Selecting by class worked fine at the end. I was doing something wrong. It would be cool to have the partial selector option though. Thanks!