judgegem / judge

Client-side form validation for Rails
MIT License
256 stars 41 forks source link

Tweaks to work with AuthLogic and namespaced classes #14

Closed jomontanari closed 9 years ago

jomontanari commented 10 years ago

Authlogic uses regular expression validations containing \A and \z (e.g. for email and username validation) added replacement to ^ and $ so that it works on the client side.

Using form_for with a class inside a module meant my input fields had names like module_class_name. The logic to get the module name does not cope well with this, so I added an optional data attribute data-model-name to the input element. If this is present, it's used for uniqueness validations.

joecorcoran commented 10 years ago

Hey – I'm a bit snowed under this week as I just moved to Germany from the UK. Just wanted to let you know I'd seen your pull request and I'm not ignoring it.

One thing to consider is that simply replacing ^ and $ with \A and \z won't work for every user in every case (e.g. multi-line input), so it'd be nice if this was a config option.

jomontanari commented 10 years ago

Just wanted to let you know I'd seen your pull request and I'm not ignoring it.

No worries! Thanks for acknowledging.

Actually I would like to add something to make it recognise the case insensitive flag in Ruby, something else I need for Authlogic, I will add to this PR when I've done that.

One thing to consider is that simply replacing ^ and $ with \A and \z won't work for every user in every case (e.g. multi-line input), so it'd be nice if this was a config option.

Is multi-line common in validation? I kept the changes minimal since you have a comment about updating to an XRegExp plugin, so it didn't seem worth being too extensive.

Also, I was targeting a specific use case to get Judge and Authlogic playing nicely together, and this was sufficient to do that (well, it will be with the case insensitivity anyway!)

Vadorequest commented 10 years ago

Is it possible to merge this? I need the ability to specify data-model-class attr.

dannysperry commented 9 years ago

@joecorcoran #14, #34, and #36 all solve the same problem. Do you think one of these PR's is stable enough to merge until the XRegExp plugin gets integrated?

jamesmk commented 9 years ago

@jocranford I was having issues with namspaced classes too and in March my PR was merged so Judge explicitly defines the class as data-klass (https://github.com/joecorcoran/judge/pull/52). This is now in v2.0.6 and I'm wondering if this fixes your need to override the class with data-model-class?

There's still the regex issue to solve, but can you update and let me know?

thanks!

jamesmk commented 9 years ago

I just merged a regex fix from https://github.com/joecorcoran/judge/pull/36. I hate to do this, since your PR was first, but the other fixes here are creating conflicts so I'm going to close this one.