| Index: third_party/polymer/v1_0/components-chromium/iron-input/iron-input-extracted.js
|
| diff --git a/third_party/polymer/v1_0/components-chromium/iron-input/iron-input-extracted.js b/third_party/polymer/v1_0/components-chromium/iron-input/iron-input-extracted.js
|
| index ba71342b72be1b195ce4c54576f4a154549418d3..340dfc6b98c16a6af117ef02b4054d728ba74243 100644
|
| --- a/third_party/polymer/v1_0/components-chromium/iron-input/iron-input-extracted.js
|
| +++ b/third_party/polymer/v1_0/components-chromium/iron-input/iron-input-extracted.js
|
| @@ -53,18 +53,22 @@ is separate from validation, and `allowed-pattern` does not affect how the input
|
| },
|
|
|
| /**
|
| - * Set to true to prevent the user from entering invalid input. The new input characters are
|
| - * matched with `allowedPattern` if it is set, otherwise it will use the `type` attribute (only
|
| - * supported for `type=number`).
|
| + * Set to true to prevent the user from entering invalid input. If `allowedPattern` is set,
|
| + * any character typed by the user will be matched against that pattern, and rejected if it's not a match.
|
| + * Pasted input will have each character checked individually; if any character
|
| + * doesn't match `allowedPattern`, the entire pasted string will be rejected.
|
| + * If `allowedPattern` is not set, it will use the `type` attribute (only supported for `type=number`).
|
| */
|
| preventInvalidInput: {
|
| type: Boolean
|
| },
|
|
|
| /**
|
| - * Regular expression expressing a set of characters to enforce the validity of input characters.
|
| - * The recommended value should follow this format: `[a-ZA-Z0-9.+-!;:]` that list the characters
|
| - * allowed as input.
|
| + * Regular expression that list the characters allowed as input.
|
| + * This pattern represents the allowed characters for the field; as the user inputs text,
|
| + * each individual character will be checked against the pattern (rather than checking
|
| + * the entire value as a whole). The recommended format should be a list of allowed characters;
|
| + * for example, `[a-zA-Z0-9.+-!;:]`
|
| */
|
| allowedPattern: {
|
| type: String,
|
| @@ -88,6 +92,47 @@ is separate from validation, and `allowed-pattern` does not affect how the input
|
| 'keypress': '_onKeypress'
|
| },
|
|
|
| + /** @suppress {checkTypes} */
|
| + registered: function() {
|
| + // Feature detect whether we need to patch dispatchEvent (i.e. on FF and IE).
|
| + if (!this._canDispatchEventOnDisabled()) {
|
| + this._origDispatchEvent = this.dispatchEvent;
|
| + this.dispatchEvent = this._dispatchEventFirefoxIE;
|
| + }
|
| + },
|
| +
|
| + created: function() {
|
| + Polymer.IronA11yAnnouncer.requestAvailability();
|
| + },
|
| +
|
| + _canDispatchEventOnDisabled: function() {
|
| + var input = document.createElement('input');
|
| + var canDispatch = false;
|
| + input.disabled = true;
|
| +
|
| + input.addEventListener('feature-check-dispatch-event', function() {
|
| + canDispatch = true;
|
| + });
|
| +
|
| + try {
|
| + input.dispatchEvent(new Event('feature-check-dispatch-event'));
|
| + } catch(e) {}
|
| +
|
| + return canDispatch;
|
| + },
|
| +
|
| + _dispatchEventFirefoxIE: function() {
|
| + // Due to Firefox bug, events fired on disabled form controls can throw
|
| + // errors; furthermore, neither IE nor Firefox will actually dispatch
|
| + // events from disabled form controls; as such, we toggle disable around
|
| + // the dispatch to allow notifying properties to notify
|
| + // See issue #47 for details
|
| + var disabled = this.disabled;
|
| + this.disabled = false;
|
| + this._origDispatchEvent.apply(this, arguments);
|
| + this.disabled = disabled;
|
| + },
|
| +
|
| get _patternRegExp() {
|
| var pattern;
|
| if (this.allowedPattern) {
|
| @@ -128,6 +173,7 @@ is separate from validation, and `allowed-pattern` does not affect how the input
|
| if (this.preventInvalidInput && !this._patternAlreadyChecked) {
|
| var valid = this._checkPatternValidity();
|
| if (!valid) {
|
| + this._announceInvalidCharacter('Invalid string of characters not entered.');
|
| this.value = this._previousValidInput;
|
| }
|
| }
|
| @@ -188,6 +234,7 @@ is separate from validation, and `allowed-pattern` does not affect how the input
|
| var thisChar = String.fromCharCode(event.charCode);
|
| if (this._isPrintable(event) && !regexp.test(thisChar)) {
|
| event.preventDefault();
|
| + this._announceInvalidCharacter('Invalid character ' + thisChar + ' not entered.');
|
| }
|
| },
|
|
|
| @@ -210,23 +257,29 @@ is separate from validation, and `allowed-pattern` does not affect how the input
|
| * @return {boolean} True if the value is valid.
|
| */
|
| validate: function() {
|
| - // Empty, non-required input is valid.
|
| - if (!this.required && this.value == '') {
|
| - this.invalid = false;
|
| - return true;
|
| + // First, check what the browser thinks. Some inputs (like type=number)
|
| + // behave weirdly and will set the value to "" if something invalid is
|
| + // entered, but will set the validity correctly.
|
| + var valid = this.checkValidity();
|
| +
|
| + // Only do extra checking if the browser thought this was valid.
|
| + if (valid) {
|
| + // Empty, required input is invalid
|
| + if (this.required && this.value === '') {
|
| + valid = false;
|
| + } else if (this.hasValidator()) {
|
| + valid = Polymer.IronValidatableBehavior.validate.call(this, this.value);
|
| + }
|
| }
|
|
|
| - var valid;
|
| - if (this.hasValidator()) {
|
| - valid = Polymer.IronValidatableBehavior.validate.call(this, this.value);
|
| - } else {
|
| - valid = this.checkValidity();
|
| - this.invalid = !valid;
|
| - }
|
| + this.invalid = !valid;
|
| this.fire('iron-input-validate');
|
| return valid;
|
| - }
|
| + },
|
|
|
| + _announceInvalidCharacter: function(message) {
|
| + this.fire('iron-announce', { text: message });
|
| + }
|
| });
|
|
|
| /*
|
|
|