Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve input values in cache #70

Closed

Conversation

entretechno-jeremiah
Copy link
Contributor

This change will save the values of <input>s, <textarea>s, and <select>s when creating a snapshot so that when you navigate back or forward in history, form fields will not be reset.

This behavior was already present prior to 5dfc79e for <input>s and <textarea>s but not <select>s (see turbolinks/turbolinks#238).

@tleish
Copy link
Contributor

tleish commented Jan 27, 2021

@entretechno-jeremiah

Several questions on this PR:

  1. With <input>, does it support all types (text, checkbox, radio, hidden, file, etc)
  2. With <input>, does it skip caching input type="password" for security purposes.
  3. Does it support both <select> one and <select multiple>?
  4. Does it support <input type="reset" value="Reset"> and allow a user to reset the form to original values prior to user input?
  5. Can I disable caching of an individual field?
<input... data-turbolinks="false">

<form data-turbolinks="false">
  <input ...>
</form>

@entretechno-jeremiah
Copy link
Contributor Author

@tleish Very good questions. It looks like they've since reverted to cloneNode(true), which makes it work with <input>s/<textarea>s, so I'll be updating this PR to account for that.

  1. In my testing, yes it does.
  2. No, but good thought. I'll be pushing out an update that does this.
  3. No, good catch. I'll be updating this as well.
  4. Yes, and I'll be adding a test to assert this.
  5. No, but I feel like this is potentially a broader request than just the values of form fields; I think this could apply to any properties/data of any element. I'd welcome some input from the maintainers on if I should add some such functionality though.

@tleish
Copy link
Contributor

tleish commented Jan 28, 2021

@entretechno-jeremiah — FYI, a while back I created an addon library that addresses the above mentioned items. Embedding it into turbo is a much better. An embedded solution also simplifies the approach since the values do not need to be temporarily written to the dom in a data field for caching purposes.

see: https://github.com/tleish/turbo-bfcache-form

The unit tests in this lib might be helpful to consider various scenarios I ran into while creating the library.

This library accomplished item 5 with

if (element.closest('[data-turbo="false"]')) {
  return false;
}

@seanpdoyle seanpdoyle added the enhancement New feature or request label Apr 1, 2021
@dhh
Copy link
Member

dhh commented Jul 18, 2022

This was left sitting for a long time. If you're still interested, I'd like to see it rebased, so we can merge.

@dhh dhh added needs rebase and removed enhancement New feature or request labels Jul 18, 2022
@tleish
Copy link
Contributor

tleish commented Aug 4, 2022

@entretechno-jeremiah - are you able to rebase this?

@entretechno-jeremiah
Copy link
Contributor Author

entretechno-jeremiah commented Aug 4, 2022 via email

@seanpdoyle
Copy link
Contributor

I'm happy to pick this branch up and move it forward.

seanpdoyle pushed a commit to seanpdoyle/turbo that referenced this pull request Aug 4, 2022
Re-submission of hotwired#70

This change will save the values of `<input>`s, `<textarea>`s, and
`<select>`s when creating a snapshot so that when you navigate back or
forward in history, form fields will not be reset.

This behavior was already present prior to [5dfc79e][] for `<input>`s
and `<textarea>`s but not `<select>`s (see
[turbolinks/turbolinks#238][]).

[5dfc79e]: hotwired@5dfc79e
[turbolinks/turbolinks#238]: turbolinks/turbolinks#238)
seanpdoyle pushed a commit to seanpdoyle/turbo that referenced this pull request Aug 4, 2022
Re-submission of hotwired#70

This change will save the values of `<input>`s, `<textarea>`s, and
`<select>`s when creating a snapshot so that when you navigate back or
forward in history, form fields will not be reset.

This behavior was already present prior to [5dfc79e][] for `<input>`s
and `<textarea>`s but not `<select>`s (see
[turbolinks/turbolinks#238][]).

[5dfc79e]: hotwired@5dfc79e
[turbolinks/turbolinks#238]: turbolinks/turbolinks#238
@seanpdoyle
Copy link
Contributor

I've opened #666 to re-submit this changeset. It's rebased off the latest main, and retains @entretechno-jeremiah authorship.

seanpdoyle pushed a commit to seanpdoyle/turbo that referenced this pull request Aug 5, 2022
Re-submission of hotwired#70

This change will save the values of `<input>`s, `<textarea>`s, and
`<select>`s when creating a snapshot so that when you navigate back or
forward in history, form fields will not be reset.

This behavior was already present prior to [5dfc79e][] for `<input>`s
and `<textarea>`s but not `<select>`s (see
[turbolinks/turbolinks#238][]).

[5dfc79e]: hotwired@5dfc79e
[turbolinks/turbolinks#238]: turbolinks/turbolinks#238
dhh pushed a commit that referenced this pull request Aug 5, 2022
Re-submission of #70

This change will save the values of `<input>`s, `<textarea>`s, and
`<select>`s when creating a snapshot so that when you navigate back or
forward in history, form fields will not be reset.

This behavior was already present prior to [5dfc79e][] for `<input>`s
and `<textarea>`s but not `<select>`s (see
[turbolinks/turbolinks#238][]).

[5dfc79e]: 5dfc79e
[turbolinks/turbolinks#238]: turbolinks/turbolinks#238

Co-authored-by: Jeremiah <jeremiah@entretechno.com>
@dhh dhh closed this Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

4 participants