jwaliszko / ExpressiveAnnotations

Annotation-based conditional validation library.
MIT License
351 stars 124 forks source link

Moving marker class "ea-triggers-bound" to html attribute #174

Open StuartMoore opened 7 years ago

StuartMoore commented 7 years ago

We're trying to keep our HTML classes to be for styling only, and move all js "markers" to being HTML attributes. The ExpressiveAnnotations.Validate.js adds "ea-triggers-bound" to the class of elements to mark that they've been bound to avoid binding twice - and as far as I can see, this is the only usage.

What are your thoughts on moving this to either jquery.data() or an html attribute? Would you accept a pull request to do so? Do you think that it's necessary to default to the current behaviour in case anyone uses the class for styling, but the behaviour could be configured using an option?

jwaliszko commented 7 years ago

The ea-triggers-bound class has been added as a result of this pull request: https://github.com/jwaliszko/ExpressiveAnnotations/pull/76

It is only a marker used for internal purposes. As you've noticed, it prevents element from subsequent re-bindings, if validation handler has been already attached to such an element. Nevertheless, if you call ea.settings.apply({ dependencyTriggers: 'new set of events' }) re-binding will be enforced. It's useful when you want to dynamically change the type of validation handlers, or when some new input elements have been dynamically added to the form in the meantime, and need to have their handlers attached.

I'd say styling based on that class is rather uncommon, if any. I don't mind pull requests refactoring this part, and I think configurability is rather redundant here.

I'm not familiar with the latest standards though - are the class markers used for JS purposes considered slightly deprecated currently, e.g. in favour of custom HTML attributes or jquery.data()?

@theyetiman, what is your thinking related to this one? Thanks.