Modify Text When Typing inside Text Box #785
-
Just a quick question I am not grasping really well: How do I modify the actual text of the text box? I can get the value I want to modify...
But, not really sure how to correctly change it. My program has a How can I change the text of the text_input? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
You need an additional struct member for your text value (String). struct MyStruct {
text_input: text_input::State,
text_value: String,
}
#[derive(Debug, Clone)]
enum Message {
InputChanged(String),
}
impl Sandbox for MyStruct {
type Message = Message;
fn new() -> Self {
Self::default()
}
fn title(&self) -> String {
String::from("MyApp")
}
fn update(&mut self, message: Message) {
match message {
Message::InputChanged(value) => {
self.text_value = s;
}
}
}
fn view(&mut self) -> Element<Message> {
let search_field = TextInput::new(
&mut self.text_input, // The previously declared state
"Some place holder",
&self.text_value, // The string to be used on each update
Message::InputChanged, // What happens on changed
);
// Rest of your GUI
} |
Beta Was this translation helpful? Give feedback.
-
Hi all |
Beta Was this translation helpful? Give feedback.
You need an additional struct member for your text value (String).
This should then be used in your update method for your struct.