diff --git a/components/lib/inputotp/InputOtp.vue b/components/lib/inputotp/InputOtp.vue index 9522cb48d..21bdda87e 100755 --- a/components/lib/inputotp/InputOtp.vue +++ b/components/lib/inputotp/InputOtp.vue @@ -1,20 +1,21 @@ @@ -41,6 +42,20 @@ export default { } }, methods: { + getTemplateAttrs(index) { + return { + value: this.tokens[index] + }; + }, + getTemplateEvents(index) { + return { + input: (event) => this.onInput(event, index), + keydown: (event) => this.onKeyDown(event), + focus: (event) => this.onFocus(event), + blur: (event) => this.onBlur(event), + paste: (event) => this.onPaste(event) + }; + }, getPTOptions(key) { const _ptm = key === 'root' ? this.ptmi : this.ptm; @@ -51,9 +66,15 @@ export default { } }); }, - onInput(event) { - this.moveToNext(event); + onInput(event, index) { + this.tokens[index] = event.target.value; this.updateModel(event); + + if (event.inputType === 'deleteContentBackward') { + this.moveToPrev(event); + } else if (event.inputType === 'insertText' || event.inputType === 'deleteContentForward') { + this.moveToNext(event); + } }, updateModel(event) { const newValue = this.tokens.join(''); @@ -87,7 +108,7 @@ export default { onBlur(event) { this.$emit('blur', event); }, - onKeyDown(event, index) { + onKeyDown(event) { const keyCode = event.keyCode; switch (keyCode) { @@ -109,14 +130,6 @@ export default { break; - case 8: - event.preventDefault(); - this.tokens[index] = ''; - this.moveToPrev(event); - this.updateModel(event); - - break; - default: if (this.integerOnly && !(event.keyCode >= 48 && event.keyCode <= 57)) { event.preventDefault(); diff --git a/doc/inputotp/TemplateDoc.vue b/doc/inputotp/TemplateDoc.vue new file mode 100644 index 000000000..2d201686d --- /dev/null +++ b/doc/inputotp/TemplateDoc.vue @@ -0,0 +1,124 @@ + + + + + diff --git a/pages/inputotp/index.vue b/pages/inputotp/index.vue index 53fbc89d0..6cb5376c0 100644 --- a/pages/inputotp/index.vue +++ b/pages/inputotp/index.vue @@ -7,6 +7,7 @@ import AccessibilityDoc from '@/doc/inputotp/AccessibilityDoc.vue'; import BasicDoc from '@/doc/inputotp/BasicDoc.vue'; import ImportDoc from '@/doc/inputotp/ImportDoc.vue'; import MaskDoc from '@/doc/inputotp/MaskDoc.vue'; +import TemplateDoc from '@/doc/inputotp/TemplateDoc.vue'; import IntegerOnlyDoc from '@/doc/inputotp/integerOnlyDoc.vue'; import PTComponent from '@/doc/inputotp/pt/index.vue'; import ThemingDoc from '@/doc/inputotp/theming/index.vue'; @@ -35,6 +36,11 @@ export default { label: 'Integer Only', component: IntegerOnlyDoc }, + { + id: 'template', + label: 'Template', + component: TemplateDoc + }, { id: 'accessibility', label: 'Accessibility',