Closed VitorHP closed 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:
validate()
in the past was annoying, because everyone had to also add the this.invalid = !valid
line, which leads to sadnessvalidate()
does that assignment for you. If your element uses a validator (like I believe gold-cc-expiration-input
does), you don't have to do anything. If your element doesn't use a validator, you should stop overriding validate()
and override _getValidity()
insteadIronValidatableBehavior
's validate()
method will call your custom implementation of _getValidity
gold-cc-input
, I think a s/validate/_getValidity
should me mostly enough (and clean up the now-uneccessary this.invalid
assignmentNow, 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!
(Closing, since I think I answered the question. Please re-open if you have more questions!)
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:Even that seems wrong since the code in
_getValidity(value)
checks for the existence of something inthis._validator
and callsvalidate()
on that ifthis._validator
is present.So, concluding, shouldn't this element just put an object which responds to
validate()
inthis._validator
and let IronValidatableBehavior do its thing?If that's the case, I'd be happy to do a PR.