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

Commit

Permalink
Merge pull request #18 from samccone/sjs/add-validation-ui
Browse files Browse the repository at this point in the history
Sjs/add validation ui
  • Loading branch information
Yvonne Yip committed Jul 16, 2014
2 parents 7b3619f + a6359b7 commit 759f149
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
6 changes: 1 addition & 5 deletions core-input.html
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,7 @@

invalidChanged: function() {
this.classList.toggle('invalid', this.invalid);
if (this.invalid) {
this.fire('input-invalid', {value: this.inputValue});
} else {
this.fire('input-valid', {value: this.inputValue});
}
this.fire('input-'+ this.invalid ? 'invalid' : 'valid', {value: this.inputValue});
},

inputValueChanged: function() {
Expand Down
15 changes: 13 additions & 2 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
margin: 1em;
}

#singleValidation.invalid {
border: solid 1px red;
}

#singleValidation {
border: solid 1px lime;
}

core-input[multiline] {
border: 1px dotted #ccc;
}
Expand Down Expand Up @@ -69,14 +77,17 @@
});
</script>
</section>

<section horizontal start layout>
<aside>This is an example of a single-line text input with number validation. See console for validation errors.</aside>
<aside>This is an example of a single-line text input with number validation. The border color reflects the current validation state. See console for validation errors or validity.</aside>
<core-input id="singleValidation" placeholder="Only enter numbers..." validate="^[0-9]*$"></core-input>
<script>
document.getElementById('singleValidation').addEventListener('input-invalid', function(e, value, s) {
console.log('singleValidation: input invalid! value:', e.detail.value);
});
document.getElementById('singleValidation').addEventListener('input-valid', function(e, value, s) {
console.log('singleValidation: input valid! value:', e.detail.value);
});
</script>
</section>

Expand Down

0 comments on commit 759f149

Please sign in to comment.