I am a django developer, and I am trying have you try to implement a form in stimulus? I’m a bit confused with something, let me explain.
I felt that stimulus encourages us to use html over json. So for example, in a todo app, if I have a form to create a new task - when I submit with a valid input, I return from the server the html with that task and insert that html in the task list.
That one feels great, but what about when the form gets an error? Here I’m says errors from the server, like the task has already another with the same name for example. You return an html with the errors too?
When you choose to use stimulus over turbo links? What your thoughts about that?
When you choose to use stimulus over turbo links? What your thoughts about that?
You can use stimulus and turbolinks together. They are designed to work well with each other.
Here I’m says errors from the server, like the task has already another with the same name for example. You return an html with the errors too?
That is one option, yes. If you are using turbolinks you can just make a POST and get a new page back, leaving turbolinks to handle the page refresh so it feels fast.
Okay, Thanks for share. I’ve made a version more less with that idea if I understand it wright.
With that approach I have to create an extra target, because if I print the error from the server (for example the field is required) when i submit again with a value the error message don’t disappear.
With that extra target it works, but maybe here, with turbo links make it nicer.
With the following code if it passes clears the error message if exists and append the new task on the current one. If it fails it renders the partial template with the input and the error.
Maybe this one type of project a todo list has a bit more logic to just use stimulus, with the addition of turbo links simplify the code. For sites more simples when you just need some simple “sprinkles” using stimulus standalone it enough.