| 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 4e9067afbc9314a737806ab09453089aacc35d8a..09f0053b56d78e9b0c929ebb42846eacf8b8aa12 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
|
| @@ -73,13 +73,18 @@ is separate from validation, and `allowed-pattern` does not affect how the input
|
| _previousValidInput: {
|
| type: String,
|
| value: ''
|
| + },
|
| +
|
| + _patternAlreadyChecked: {
|
| + type: Boolean,
|
| + value: false
|
| }
|
|
|
| },
|
|
|
| listeners: {
|
| 'input': '_onInput',
|
| - 'keydown': '_onKeydown'
|
| + 'keypress': '_onKeypress'
|
| },
|
|
|
| get _patternRegExp() {
|
| @@ -104,33 +109,54 @@ is separate from validation, and `allowed-pattern` does not affect how the input
|
|
|
| _bindValueChanged: function() {
|
| if (this.value !== this.bindValue) {
|
| - this.value = this.bindValue;
|
| + this.value = !this.bindValue ? '' : this.bindValue;
|
| }
|
| // manually notify because we don't want to notify until after setting value
|
| this.fire('bind-value-changed', {value: this.bindValue});
|
| },
|
|
|
| _onInput: function() {
|
| - this.bindValue = this.value;
|
| - },
|
| + // Need to validate each of the characters pasted if they haven't
|
| + // been validated inside `_onKeypress` already.
|
| + if (this.preventInvalidInput && !this._patternAlreadyChecked) {
|
| + var valid = this._checkPatternValidity();
|
| + if (!valid) {
|
| + this.value = this._previousValidInput;
|
| + }
|
| + }
|
|
|
| - _isPrintable: function(keyCode) {
|
| - var printable =
|
| - (keyCode > 47 && keyCode < 58) || // number keys
|
| - keyCode == 32 || keyCode == 13 || // spacebar & return key
|
| - (keyCode > 64 && keyCode < 91) || // letter keys
|
| - (keyCode > 95 && keyCode < 112) || // numpad keys
|
| - (keyCode > 185 && keyCode < 193) || // ;=,-./` (in order)
|
| - (keyCode > 218 && keyCode < 223); // [\]' (in order)
|
| - return printable;
|
| + this.bindValue = this.value;
|
| + this._previousValidInput = this.value;
|
| + this._patternAlreadyChecked = false;
|
| },
|
|
|
| - // convert printable numpad keys to number keys
|
| - _correctNumpadKeys: function(keyCode) {
|
| - return (keyCode > 95 && keyCode < 112) ? keyCode - 48 : keyCode;
|
| + _isPrintable: function(event) {
|
| + // What a control/printable character is varies wildly based on the browser.
|
| + // - most control characters (arrows, backspace) do not send a `keypress` event
|
| + // in Chrome, but the *do* on Firefox
|
| + // - in Firefox, when they do send a `keypress` event, control chars have
|
| + // a charCode = 0, keyCode = xx (for ex. 40 for down arrow)
|
| + // - printable characters always send a keypress event.
|
| + // - in Firefox, printable chars always have a keyCode = 0. In Chrome, the keyCode
|
| + // always matches the charCode.
|
| + // None of this makes any sense.
|
| +
|
| + var nonPrintable =
|
| + (event.keyCode == 8) || // backspace
|
| + (event.keyCode == 19) || // pause
|
| + (event.keyCode == 20) || // caps lock
|
| + (event.keyCode == 27) || // escape
|
| + (event.keyCode == 45) || // insert
|
| + (event.keyCode == 46) || // delete
|
| + (event.keyCode == 144) || // num lock
|
| + (event.keyCode == 145) || // scroll lock
|
| + (event.keyCode > 32 && event.keyCode < 41) || // page up/down, end, home, arrows
|
| + (event.keyCode > 111 && event.keyCode < 124); // fn keys
|
| +
|
| + return !(event.charCode == 0 && nonPrintable);
|
| },
|
|
|
| - _onKeydown: function(event) {
|
| + _onKeypress: function(event) {
|
| if (!this.preventInvalidInput && this.type !== 'number') {
|
| return;
|
| }
|
| @@ -138,22 +164,45 @@ is separate from validation, and `allowed-pattern` does not affect how the input
|
| if (!regexp) {
|
| return;
|
| }
|
| - var thisChar = String.fromCharCode(this._correctNumpadKeys(event.keyCode));
|
| - if (this._isPrintable(event.keyCode) && !regexp.test(thisChar)) {
|
| +
|
| + // Handle special keys and backspace
|
| + if (event.metaKey || event.ctrlKey || event.altKey)
|
| + return;
|
| +
|
| + // Check the pattern either here or in `_onInput`, but not in both.
|
| + this._patternAlreadyChecked = true;
|
| +
|
| + var thisChar = String.fromCharCode(event.charCode);
|
| + if (this._isPrintable(event) && !regexp.test(thisChar)) {
|
| event.preventDefault();
|
| }
|
| },
|
|
|
| + _checkPatternValidity: function() {
|
| + var regexp = this._patternRegExp;
|
| + if (!regexp) {
|
| + return true;
|
| + }
|
| + for (var i = 0; i < this.value.length; i++) {
|
| + if (!regexp.test(this.value[i])) {
|
| + return false;
|
| + }
|
| + }
|
| + return true;
|
| + },
|
| +
|
| /**
|
| * Returns true if `value` is valid. The validator provided in `validator` will be used first,
|
| * then any constraints.
|
| - * @return {Boolean} True if the value is valid.
|
| + * @return {boolean} True if the value is valid.
|
| */
|
| validate: function() {
|
| // Empty, non-required input is valid.
|
| - if (!this.required && this.value == '')
|
| + if (!this.required && this.value == '') {
|
| + this.invalid = false;
|
| return true;
|
| -
|
| + }
|
| +
|
| var valid;
|
| if (this.hasValidator()) {
|
| valid = Polymer.IronValidatableBehavior.validate.call(this, this.value);
|
|
|