Turbo Frames - Inline Edit

Manage Inline Editing with Turbo Frames and Cookies

View Solution on Patreon
Turbo Frames - Inline Edit

Premise

Inline Editing is a UX pattern that is frequently used to reduce the friction for updating records, but can come with some pitfalls. In this challenge, we will employ Turbo Frames to do the heavy lifting, and add some usability sprinkles.

Starting Point

This challenge features a single Turbo Frame which is loaded from the /title route via a GET request:

https://stackblitz.com/edit/turbo-frames-inline-editing?file=index.html%3AL43

The underlying node.js script relies on a “poor mans templating engine” to substitute a template string ({{title}}) in the link.html file (think of this as a “partial”):

https://stackblitz.com/edit/turbo-frames-inline-editing?file=index.js%3AL19

In said file, a <turbo-frame> tag encloses a hyperlink to the /title/edit route:

https://stackblitz.com/edit/turbo-frames-inline-editing?file=link.html

This route in turn renders the other “partial”, form.html:

https://stackblitz.com/edit/turbo-frames-inline-editing?file=index.js%3AL37

Challenge

Your challenge this time is to

  1. Complete form.html so that it issues a PATCH request to /title which will in turn redirect to /title again ( https://stackblitz.com/edit/turbo-frames-inline-editing?file=index.js%3AL20) )

  2. In app.js, make sure that

  • whenever you enable editing, the whole text is selected
  • the form is submitted when you focus out of the input

Here’s a preview:

A demo of inline editing a text field

Teaser

When you refresh your browser after enabling the text field, it is again disabled. How would store this state?

More from

Faceted Search with Stimulus and Turbo Frames
10 December 2024

Harness the power of Stimulus and Turbo Frames to drive a simple but powerful faceted search solution

Turbo Frames - Markdown Preview
08 October 2024

Typeahead previews of markdown by simple Turbo Frame rerendering

Turbo Frames - Render Flash Messages Upon Form Submission
27 August 2024

Intercept form submission responses to render flash messages that are outside the originating Turbo Frame

Cookies
essential