Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
implement validateImmediately and better number input
Browse files Browse the repository at this point in the history
  • Loading branch information
Yvonne Yip committed Aug 22, 2014
1 parent 2a423e3 commit d2d9dea
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions core-input.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
</template>

<template if="{{!multiline}}">
<input id="input" value="{{inputValue}}" disabled?="{{disabled}}" type="{{type}}" placeholder="{{placeholder}}" autofocus?="{{autofocus}}" required?="{{required}}" readonly?="{{readonly}}" pattern="{{pattern}}" min="{{min}}" max="{{max}}" step="{{step}}" maxlength="{{maxlength}}" aria-label="{{label || placeholder}}" aria-invalid="{{invalid}}" on-keydown="{{keydownAction}}" on-change="{{inputChangeAction}}" on-focus="{{inputFocusAction}}" on-blur="{{inputBlurAction}}">
<input id="input" value="{{inputValue}}" disabled?="{{disabled}}" type="{{type}}" placeholder="{{placeholder}}" autofocus?="{{autofocus}}" required?="{{required}}" readonly?="{{readonly}}" pattern="{{pattern}}" min="{{min}}" max="{{max}}" step="{{step}}" maxlength="{{maxlength}}" aria-label="{{label || placeholder}}" aria-invalid="{{invalid}}" on-keypress="{{keypressAction}}" on-change="{{inputChangeAction}}" on-focus="{{inputFocusAction}}" on-blur="{{inputBlurAction}}">
</template>

</template>
Expand Down Expand Up @@ -293,15 +293,19 @@
},

inputValueChanged: function() {
this.updateValidity_();
if (this.validateImmediately) {
this.updateValidity_();
}
},

valueChanged: function() {
this.inputValue = this.value;
},

requiredChanged: function() {
this.updateValidity_();
if (this.validateImmediately) {
this.updateValidity_();
}
},

attributeChanged: function(attr, oldVal, curVal) {
Expand Down Expand Up @@ -333,13 +337,14 @@
}
},

keydownAction: function() {
// for type = number, the value is the empty string unless the input is a valid number.
// FIXME(yvonne): check other types
if (this.type === 'number') {
this.async(function() {
this.updateValidity_();
});
keypressAction: function(e) {
// disallow non-numeric input if type = number
if (this.type !== 'number') {
return;
}
var c = String.fromCharCode(e.charCode);
if (!c.match(/[\d-\.e]/)) {
e.preventDefault();
}
},

Expand Down

0 comments on commit d2d9dea

Please sign in to comment.