Skip to content

Commit

Permalink
Added pattern prop for regex validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
martywallace committed Dec 14, 2016
1 parent b278447 commit 31b3ff5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dist/vue-keyboard.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion src/vue-keyboard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(() => {
Vue.component('keyboard', {
template: `<aside class="vue-keyboard" role="application" :class="{ full: full, empty: empty }" :data-value="value" :data-layout="layout">
template: `<aside class="vue-keyboard" role="application" :class="{ full: full, empty: empty, valid: valid, invalid: !valid }" :data-value="value" :data-layout="layout">
<div role="row" class="row" v-for="row in buttons" :data-keys="row.length">
<button
v-for="btn in row"
Expand All @@ -27,6 +27,10 @@
type: Number,
default: 0,
validator(value) { return value >= 0; }
},
pattern: {
type: String,
default: null
}
},

Expand Down Expand Up @@ -102,6 +106,15 @@

return buttons;
});
},

/**
* Whether or not the current value matches the regex provided to pattern. Always
* returns true if no pattern was provided.
* @returns {Boolean}
*/
valid() {
return !this.pattern || this.value.match(new RegExp(this.pattern));
}
},

Expand Down

0 comments on commit 31b3ff5

Please sign in to comment.