Repository navigation
Keep field values the user changed while a morph request was out - #4222
Open
SahinurDEV wants to merge 1 commit into
Open
SahinurDEV wants to merge 1 commit into
SahinurDEV wants to merge 1 commit into
Conversation
Morph only kept the value of the focused field. A user who typed while the request was out and then moved focus lost that text to the response. Treat a field's value as the user's when it differs from the value the request sent for it. Fixes bigskysoftware#4184
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Morph keeps the value of the focused field while a response lands (#3985). If the user types while the request is out and then moves focus (Tab, or a click into the next field) before the response arrives, the response's
valueis written into.valueand the newer text is lost. Withhx-trigger="input changed delay:…"that text is never sent either:changedsees the reverted value and drops the debounced request.This takes the rule suggested in the issue. A field holds the user's value when it is focused (as before) or when its current value isn't one the request sent for its
name. In that case morph still updates thevalueattribute but leaves.valuealone. The textarea path uses the same check.ctx.sentValuesright afterhtmx:config:request, before GET/DELETE move it into the query string, and passed to the morph through the swap tasks.htmx.swap(), SSE), behave as before.ab→Ab) still wins.sentValuestoHtmxRequestCtxinhtmx.d.ts, and a paragraph to the morphing guide.Corresponding issue: #4184
Testing
Added 3 tests to
test/tests/unit/morph.js(input value preservation):keeps text typed while the request was out after the input loses focus: thehx-postform from the issue. Inhtmx:before:swapthe input getsabcdand focus moves to the next field..valuestaysabcdand thevalueattribute becomesab.keeps a textarea edited while the request was out after it loses focus: the same for a textarea sent withhx-get+hx-include, so the values go through the query string.applies the response value to an input the user did not change since the request: a normalized value replaces the sent one, and an input the request didn't carry takes the response value.The first two fail on
four-devwithout the change (expected 'ab' to equal 'abcd',expected 'first' to equal 'first draft') and pass with it.npm test(Chromium): 88 files, 1848 passed, 0 failed, 4 skipped, 100% coverage.npm run check:contentpasses.Checklist
masterfor website changes,devforsource changes)
approved via an issue
npm run test) and verified that it succeeded