From abfd15d07538fcd02fd6288d1fc4eb82b19f30e1 Mon Sep 17 00:00:00 2001 From: Cagatay Civici Date: Thu, 22 Feb 2024 09:40:19 +0300 Subject: [PATCH] Add template sample to inputotp --- components/lib/inputotp/InputOtp.vue | 65 ++++++++------ doc/inputotp/TemplateDoc.vue | 124 +++++++++++++++++++++++++++ pages/inputotp/index.vue | 6 ++ 3 files changed, 169 insertions(+), 26 deletions(-) create mode 100644 doc/inputotp/TemplateDoc.vue 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',