Skip to content

Commit 44a66f7

Browse files
committed
refactor: 增加同步逻辑
1 parent c33c3a2 commit 44a66f7

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/BootstrapBlazor/Components/Input/OtpInput.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@inherits ValidateBase<string>
33

44
<div @attributes="AdditionalAttributes" id="@Id" class="@ClassString">
5-
<input hidden value="@CurrentValueAsString" class="opt-input-val" />
5+
<input hidden value="@CurrentValueAsString" class="bb-opt-input-val" />
66
@for (var index = 0; index < Digits; index++)
77
{
88
@if(IsReadonly || IsDisabled)

src/BootstrapBlazor/Components/Input/OtpInput.razor.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
export function init(id) {
44
const el = document.getElementById(id);
5+
const input = el.querySelector('.bb-opt-input-val');
56
const skipKeys = ['Enter', 'Tab', 'Shift', 'Control', 'Alt'];
67
EventHandler.on(el, 'input', '.bb-opt-item', e => {
78
const isNumber = e.target.getAttribute('type') === 'number';
@@ -10,6 +11,7 @@ export function init(id) {
1011
e.target.value = e.target.value.slice(1, 2);
1112
}
1213
}
14+
input.value = [...el.querySelectorAll('.bb-opt-item')].map(input => input.value).join('');
1315
});
1416
EventHandler.on(el, 'keydown', '.bb-opt-item', e => {
1517
const isNumber = e.target.getAttribute('type') === 'number';

0 commit comments

Comments
 (0)