feat(frontend): adds oninput to input fields for Mobile support
This commit is contained in:
parent
043db74ea2
commit
4c2bb68c4d
@ -254,13 +254,12 @@ pub fn Home() -> Html {
|
||||
let input_values = input_values.clone();
|
||||
let node_refs = node_refs.clone();
|
||||
|
||||
Callback::from(move |e: KeyboardEvent| {
|
||||
match e.key().as_ref() {
|
||||
Callback::from(move |e: KeyboardEvent| match e.key().as_ref() {
|
||||
"Enter" => {
|
||||
if let Ok(m) = MouseEvent::new("click") {
|
||||
on_submit.emit(m);
|
||||
}
|
||||
},
|
||||
}
|
||||
"Backspace" => {
|
||||
e.prevent_default();
|
||||
|
||||
@ -269,31 +268,92 @@ pub fn Home() -> Html {
|
||||
|
||||
values[index] = String::new();
|
||||
input_values.set(values);
|
||||
if node_refs[index].cast::<web_sys::HtmlInputElement>().is_some() && index > 0 {
|
||||
if node_refs[index]
|
||||
.cast::<web_sys::HtmlInputElement>()
|
||||
.is_some()
|
||||
&& index > 0
|
||||
{
|
||||
let index = index - 1;
|
||||
curr_index.set(index);
|
||||
set_focus(index);
|
||||
}
|
||||
},
|
||||
k if k.len() == 1 && k.chars().all(char::is_alphabetic) => {
|
||||
}
|
||||
k => {
|
||||
let index = *curr_index;
|
||||
let mut values = (*input_values).clone();
|
||||
|
||||
if k.len() == 1 && k.chars().all(char::is_alphabetic) {
|
||||
values[index] = k.to_uppercase();
|
||||
input_values.set(values);
|
||||
if node_refs[index].cast::<web_sys::HtmlInputElement>().is_some() && index < *length {
|
||||
if node_refs[index]
|
||||
.cast::<web_sys::HtmlInputElement>()
|
||||
.is_some()
|
||||
&& index < *length
|
||||
{
|
||||
let index = index + 1;
|
||||
curr_index.set(index);
|
||||
set_focus(index);
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
} else {
|
||||
values[index] = String::new();
|
||||
input_values.set(values);
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
let on_input = {
|
||||
let curr_index = curr_index.clone();
|
||||
let length = length.clone();
|
||||
let on_submit = on_submit.clone();
|
||||
let input_values = input_values.clone();
|
||||
let node_refs = node_refs.clone();
|
||||
|
||||
Callback::from(move |e: InputEvent| {
|
||||
let event = e.dyn_into::<web_sys::KeyboardEvent>().ok();
|
||||
if let Some(e) = event.as_ref() {
|
||||
match e.key().as_ref() {
|
||||
"Enter" => {
|
||||
if let Ok(m) = MouseEvent::new("click") {
|
||||
on_submit.emit(m);
|
||||
}
|
||||
}
|
||||
"Backspace" => {
|
||||
let index = *curr_index;
|
||||
let mut values = (*input_values).clone();
|
||||
values[index] = String::new();
|
||||
input_values.set(values);
|
||||
if node_refs[index]
|
||||
.cast::<web_sys::HtmlInputElement>()
|
||||
.is_some()
|
||||
&& index > 0
|
||||
{
|
||||
let index = index - 1;
|
||||
curr_index.set(index);
|
||||
set_focus(index);
|
||||
}
|
||||
}
|
||||
k => {
|
||||
let index = *curr_index;
|
||||
let mut values = (*input_values).clone();
|
||||
|
||||
if k.len() == 1 && k.chars().all(char::is_alphabetic) {
|
||||
values[index] = k.to_uppercase();
|
||||
input_values.set(values);
|
||||
if node_refs[index]
|
||||
.cast::<web_sys::HtmlInputElement>()
|
||||
.is_some()
|
||||
&& index < *length
|
||||
{
|
||||
let index = index + 1;
|
||||
curr_index.set(index);
|
||||
set_focus(index);
|
||||
}
|
||||
} else {
|
||||
values[index] = String::new();
|
||||
input_values.set(values);
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
@ -411,6 +471,7 @@ pub fn Home() -> Html {
|
||||
html! {
|
||||
<input
|
||||
onkeyup={on_enter.clone()}
|
||||
oninput={on_input.clone()}
|
||||
tabindex={index.to_string()}
|
||||
ref={node_ref.clone()}
|
||||
value={input_values[index].clone()}
|
||||
|
Loading…
x
Reference in New Issue
Block a user