Skip to content

Modify Text When Typing inside Text Box #785

Answered by GiulianoCTRL
Evilsmaher asked this question in Q&A
Discussion options

You must be logged in to vote

You need an additional struct member for your text value (String).
This should then be used in your update method for your struct.

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

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
8 replies
@13r0ck
Comment options

@13r0ck
Comment options

@Evilsmaher
Comment options

@13r0ck
Comment options

@Evilsmaher
Comment options

Answer selected by hecrj
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants
Converted from issue

This discussion was converted from issue #784 on March 18, 2021 12:08.