-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting the current value of an input? #233
Comments
Edit: Ignore the above post, turns out I had a different issue. What I'm trying to do is make it so you can type anything, but if the string contains 12345, anything you type after dosen't appear. What actually happens is it dosen't get set in self.seed which is good, but it still appears in the textbox, which is bad. Any idea whats wrong? https://gist.github.com/rust-play/e8adec2f576aae085f4aae4c8caa32cf. I would think that self.seed would stay the same, and since Msg::SetSeed returns true, it triggers an update for the value attribute on the textfield |
I'm having this issue with a textarea - I want to record my thoughts (but I've not yet looked at the internals of this part of yew yet). All of the following is speculation: My suspicion is that yew keeps around the last applied virtual dom (let's call it I think the solution is to take inspiration from react controlled components, where if you don't create an |
Did a bit more research
Edit: here's the original implementation of a controlled input component in React, back in 2013! |
I went down the list on https://github.com/flosse/rust-web-framework-comparison#frontend-frameworks-wasm Of those:
I additionally came across dominator, which has a similar problem but it offers something a little different to dom diffing and there's a straightforward (if boilerplate-heavy) workaround. |
Is there any progress done on this issue? |
There is a work-around, we should add documentation for this or make a better fix. The issue is that fn update(&mut self, msg: Self::Message) -> ShouldRender {
match msg {
Msg::OnInput(value) => {
let old_value = self.input_value.clone();
self.input_value = "".to_string();
self.link.send_self(Msg::SetInput(old_value);
true
}
Msg::SetInput(value) => {
self.input_value = value;
true
}
}
fn view(&self) -> Html<Self> {
html! { <input type="text" value={self.input_value} oninput=|e| Msg::OnInput(e.value) /> }
} |
whats the type of e in the input callback? |
or if the input type is range, to web_sys::HtmlInputElement instead of web_sys::HtmlTextAreaElement |
If I have something like
and change text_state, than the input dosen't update.
value
seems to only work for the inital value, when the component is constructedThe text was updated successfully, but these errors were encountered: