Changing attributes with a link

Hi.

İ have a form that it should disable input. But there is a link “Edit”. When i click edit, input disable attributes should change false.

p![C!{"control has-icons-left"},
   input![C!{"input"},
     attrs!{
       At::Type=>"text",
       //At::Placeholder=>"E-posta veya telefon numarası",
       // TODO: `username` vs `email`?
       At::Name=>"first_name",
       At::Id=>"first_name",
       At::Disabled => true,
       At::Value => &model.first_name,
     },
   input_ev(Ev::OnClick, "Change Disabled to false"),
]

Generally, the Elm way to do this is that you add some state to your model from which you can compute whether the form is editable (in the simplest case, this could be a boolean, but in practice, as the logic becomes more complex (toggling editing, recording the field updates in the model, validating the form, submitting the form) it can be helpful to make an enum that describes the current state of the form/page).

Then you can use that state in the view like this

let disabled = !form_is_editable(model);

...

attrs!{
    At::Disabled => disabled,
},
attrs!{
At::Type=>“text”,
At::Name=>“first_name”,
At::Id=>“first_name”,
At::Value => &model.first_name,
},
1 Like

Note:

It should be:

attrs!{
    At::Disabled => disabled.as_at_value(),
},

To convert bool to AtValue. Without it, Seed only stringifies the value, because it’s not clever enough to distinguish regular and boolean HTML attributes yet. The new API, that resolves it, is designed in this issue.

Ah, sorry about that. I should have checked the case where it is supposed to be enabled. Then I would have seen that.

Nice to hear that making this more newbie-friendly is on the agenda.

Thank you for your answer. I did not use Elm or React. Seed is my first front-end tool that i used. But i think i understand the logic. For now, i will not make complicated. I will wait Seed Hooks get stable rust.

Thank you :slight_smile:

For now, if you have never written a frontend App before and you want to understand the Elm architecture, a good idea is to learn Elm directly. Elm as a language is very simple, and the documentation is very good. A lot of what you learn about frontend development there will transfer to all kinds of other frameworks. There are many resources for Elm and they have a slack with an incredibly active #beginners channel on the Elm slack where you can often get an answer instantly or within minutes.

In practice, many people find the limitations of Elm (strictly no side-effects inside the Elm code, limited facilities for abstraction) quite restricting. Seed has none of these limitations. Rust is a language with great abstraction potential and Rust as a language doesn’t prevent you from using functions that have side-effects. This power is to be used with care. Elm makes things safe by preventing you to do certain things. Really the biggest drawback of Elm is that Elm is not a language that can run efficiently on the server. This is the main reason I can’t bring myself to use Elm for a bigger project. However, Elm is great for little components.

I think Seed has a bright future ahead of it because it takes the best parts of the Elm architecture and improves from there. Due to Rust being an amazing server-side language, and Rust also having a great WebAssembly backend, it’s possible to write very efficient apps that are type-checked by the compiler all the way between frontend and backend. This eliminates the need for a lot of (but not all) tests.

Thanks! It was my goal when I moved from Elm to Seed :slight_smile:

It’s shame that development of https://github.com/wende/elchemy is slow. I think it would help to resolve this problem. Both Elm and Elixir aren’t too fast for more complex algorithms but for multiple connected clients (e.g. websockets) it would be a very good choice. Also it may be a better option than Rust for complete beginners.

Thank you for your advice.

To be honest for a newbie rustacean or frontend devleoper(actualy i am not :slight_smile: ), i dont have time for learning Elm or any other language. Thats why i chose wasm. Learn rust, use frameworks and understand how they work. And also, i am learning slow(bad english). So, i have to do my hobby project done. Until then, i only can learn rust-tide-seed etc. Learning Elm means it, 2-3 months break for me :slight_smile:

Also, i think learning seed also have advantages. Developers know how Elm works and tring to create similar framework. So, if i could learn seed, i will understand frontend and WASM! And it will be nice :slight_smile:

Thank you again, for your help and advice.