Giter Site home page Giter Site logo

Comments (4)

weaverryan avatar weaverryan commented on July 17, 2024 1

Then, at least for now, let's go with this as the official solution 👍

from turbo.

brunoprietog avatar brunoprietog commented on July 17, 2024

As pointed out in that PR, did you try adding data-turbo-permanent to the input when focusing and removing the attribute when unfocusing? Like data-action="focus->element#makePermanent blur->element#makeNotPermanent"

from turbo.

weaverryan avatar weaverryan commented on July 17, 2024

As pointed out in that PR, did you try adding data-turbo-permanent to the input when focusing and removing the attribute when unfocusing? Like data-action="focus->element#makePermanent blur->element#makeNotPermanent"

Hi! I was more looking for "what is the proper way to handle this situation". And... maybe this is it? Maybe the idea is:

When a new page is morphed, if the user has been actively typing into an input, their new text might be replaced. To avoid, this, you can mark the input as permanent when its focused by... etc, etc.

If that's the case, should we provide an attribute for this? data-turbo-preserve-focus-value? It's a little wordy... but the hope is to allow for both situations:

A) In my form, the user hits "Enter" to submit and I redirect and re-render a clear form. So I want the focused input to have its value cleared (current behavior)
B) My form is auto-submitting as the user is typing and I DO want to keep the value in the form, even if it differs from the server.

from turbo.

brunoprietog avatar brunoprietog commented on July 17, 2024

It's simpler than that. When you focus the input, if you add the data-turbo-permanent attribute, Turbo knows that this element does not have to be touched when morphing. Therefore, it won't lose focus and the value won't change either. You just have to make sure to remove the attribute when blurring. With that you can easily cover case B. Honestly, I see it unlikely that the team would want to add something like that, since that means maintaining an API for a case that can be easily solved with Stimulus.

from turbo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.