PolymerElements / gold-cc-input

An input element that only allows credit card numbers
https://webcomponents.org/element/PolymerElements/gold-cc-input
13 stars 23 forks source link

Input declares use of IronValidatableBehavior, but uses custom validation #28

Closed VitorHP closed 9 years ago

VitorHP commented 9 years ago

Hi, guys.

I'm reading the Polymer source and was trying to build an input with custom validation and stumbled upon some strange things.

Here on the gold-cc-input, it's declared the use of IronValidatableBehavior, but the validation is made through an observer which runs the validate method.

The code on IronValidatableBehavior, says in the comments of its own validate method as quoted below:

If you want your element to have custom validation logic, do not override this method; override _getValidity(value) instead.

Even that seems wrong since the code in _getValidity(value) checks for the existence of something in this._validator and calls validate() on that if this._validator is present.

So, concluding, shouldn't this element just put an object which responds to validate() in this._validator and let IronValidatableBehavior do its thing?

If that's the case, I'd be happy to do a PR.

notwaldorf commented 9 years ago

Hiya! This is a new change, and a lot of the old code hasn't been updated. Here's a convoluted explanation:

Now, the difference between overriding _getValidity and using a validator is basically a singleton, which means it validates all inputs in the same way. This is usually ok, but in particular for gold-cc-input this doesn't work, since based on the input you have to do something with the card icon, which means you need a this pointer (which the validator does not have)

Hope this helps!

notwaldorf commented 9 years ago

(Closing, since I think I answered the question. Please re-open if you have more questions!)