4
11
Fork
You've already forked tomato
1

New form for trackers #182

Merged
edwardloveall merged 1 commit from el-tracker-create into main 2026年07月09日 15:11:01 +02:00

One thing I'm proud of here is a got an association in the form here that can be
added or removed without any javascript. Totally progressively enhanced. It
works by using a submit button that makes a GET request. The submit name is
add_shift. If the controller sees that in the params, it builds a new shift on
the tracker so it shows up in the form. accepts_nested_attributes_for :shifts_trackers, allow_destroy: true takes care of deleting when a _destroy
param is passed. It's not the best looking erb, but it's still readable.

I also added a .multiple-nested class. If there's a form with a
.multiple-nested wrapper, any .field label inside will be hidden. This is so
you don't have the label repeating for every new nested association.

Screen Shot 2026年07月07日 at 16.00.35-fullpage

One thing I'm proud of here is a got an association in the form here that can be added or removed without any javascript. Totally progressively enhanced. It works by using a submit button that makes a GET request. The submit name is `add_shift`. If the controller sees that in the params, it builds a new shift on the tracker so it shows up in the form. `accepts_nested_attributes_for :shifts_trackers, allow_destroy: true` takes care of deleting when a `_destroy` param is passed. It's not the best looking erb, but it's still readable. I also added a `.multiple-nested` class. If there's a `form` with a `.multiple-nested` wrapper, any `.field label` inside will be hidden. This is so you don't have the label repeating for every new nested association. ![Screen Shot 2026年07月07日 at 16.00.35-fullpage](/attachments/36d45404-080a-46e3-baea-d05306d047c4)
New form for trackers
Some checks failed
ci/woodpecker/pr/ci Pipeline failed
55d91f0c3c
One thing I'm proud of here is a got an association in the form here that can be
added or removed without any javascript. Totally progressively enhanced. It
works by using a submit button that makes a GET request. The submit name is
`add_shift`. If the controller sees that in the params, it builds a new shift on
the tracker so it shows up in the form. `accepts_nested_attributes_for
:shifts_trackers, allow_destroy: true` takes care of deleting when a `_destroy`
param is passed. It's not the best looking erb, but it's still readable.
I also added a `.multiple-nested` class. If there's a `form` with a
`.multiple-nested` wrapper, any `.field label` inside will be hidden. This is so
you don't have the label repeating for every new nested association.
edwardloveall force-pushed el-tracker-create from 55d91f0c3c
Some checks failed
ci/woodpecker/pr/ci Pipeline failed
to 6a5d9e7032
Some checks failed
ci/woodpecker/pr/ci Pipeline failed
2026年07月08日 16:15:17 +02:00
Compare
edwardloveall force-pushed el-tracker-create from 6a5d9e7032
Some checks failed
ci/woodpecker/pr/ci Pipeline failed
to 3ecf142d58
All checks were successful
ci/woodpecker/pr/ci Pipeline was successful
2026年07月08日 16:20:09 +02:00
Compare
jsilasbailey left a comment
Copy link

Ah, brings me back to those initial Turbo days, migh have issues including the description field in the query params unfortunately 😢

Ah, brings me back to those initial Turbo days, migh have issues including the `description` field in the query params unfortunately 😢
@ -6,0 +40,4 @@
.fetch(:tracker, {})
.permit(
:title,
:description,
First-time contributor
Copy link

If I'm remembering correctly, this approach of form GET + including rich text in the query params may run into issues with query param length limits

see Sean Doyle's dynamic forms example (bottom of linked session)

If I'm remembering correctly, this approach of form GET + including rich text in the query params may run into issues with query param length limits [see Sean Doyle's dynamic forms example (bottom of linked session)](https://github.com/thoughtbot/hotwire-example-template/tree/hotwire-example-turbo-dynamic-forms#refreshing-content-without-javascript)
Author
Owner
Copy link

Ah thanks for this. Great resource (Sean's the best). Do you know of a good solution that would keep the form progressively enhanced? Maybe POSTing to some kind of /form_update endpoint? If not, no worries. I may have to leave it like this for now and come back to it if there's time because you can still create something successfully.

Ah thanks for this. Great resource (Sean's the best). Do you know of a good solution that would keep the form progressively enhanced? Maybe POSTing to some kind of `/form_update` endpoint? If not, no worries. I may have to leave it like this for now and come back to it if there's time because you can still create something successfully.
First-time contributor
Copy link

(Agreed Sean's the best, that repo is gold)

I never really worked around it in practice. For forms like this where the user would be writing long prose that they wouldn't want to lose on refresh, I think best practice is probably to store their in-progress form on the backend and POST to it, redirecting back to the resource. That's a bit similar to a list view with a progressively enhanced modal but I don't remember ever implementing something like that and progressively enhancing to Turbo.

That extra complexity seems like a bit much though. You can probably attempt to avoid the issue by putting the description field at the end to make it likely that it's not filled in when the user is adding shifts to the form. Not a guarantee but 🤷

(Agreed Sean's the best, that repo is gold) I never really worked around it in practice. For forms like this where the user would be writing long prose that they wouldn't want to lose on refresh, I think best practice is probably to store their in-progress form on the backend and `POST` to it, redirecting back to the resource. That's a bit similar to a list view with a progressively enhanced modal but I don't remember ever implementing something like that and progressively enhancing to Turbo. That extra complexity seems like a bit much though. You can probably attempt to avoid the issue by putting the description field at the end to make it likely that it's not filled in when the user is adding shifts to the form. Not a guarantee but 🤷
edwardloveall changed target branch from el-tracker-index to main 2026年07月08日 22:43:53 +02:00
edwardloveall deleted branch el-tracker-create 2026年07月09日 15:11:02 +02:00
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
rootable/tomato!182
Reference in a new issue
rootable/tomato
No description provided.
Delete branch "el-tracker-create"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?