Skip to content

Conversation

@weaverryan
Copy link
Member

@weaverryan weaverryan commented Jul 4, 2022

Q A
Bug fix? yes
New feature? yes
Tickets None
License MIT

Hi!

tl;dr

BEFORE:
<input
    data-model="firstName"
    data-action="live#update"
>

AFTER:
<input
    data-model="firstName"
>

This PR makes it so that you only need to use data-model to bind an input to a LiveProp on your component object. This also introduces:

A) model modifiers (e.g. data-model="on(change)|norender|firstName" to update the model on change and skip re-rendering)

B) A new way to "opt in" to the name attribute being used in place of data-model: you now add a data-model to the form tag surrounding your fields: <form data-model"*">.

All of this is explained more in the CHANGELOG and documentation.

The motivation behind this change was actually to fix a bug. If you typed into field (A), then quickly typed into field (B) before the re-render Ajax request finished from changing field (A), when that Ajax call did finish, it would "replace" your custom changes to field (B). Basically, what you just typed disappears. Fixing this meant making live_controller.ts listen to the input event in all situations and track "unsynced inputs". And since we were now listening to the input event all the time, it seemed logical to no longer require the user to do this manually with data-action="live#update".

This PR also overhauls the test suite to make it much more readable and user friends 🌞 and also completes the conversion to TypeScript by removing all of the TS warnings.

Cheers!

@weaverryan weaverryan force-pushed the model-rendering-overhaul branch from 9dbad3f to be3c396 Compare July 6, 2022 19:50
@weaverryan weaverryan force-pushed the model-rendering-overhaul branch from 75aeef1 to d3aaf4f Compare July 6, 2022 20:17
@weaverryan weaverryan merged commit 6afcd61 into symfony:2.x Jul 6, 2022
weaverryan added a commit that referenced this pull request Jul 8, 2022
…any value (weaverryan)

This PR was merged into the 2.x branch.

Discussion
----------

[LiveComponent] Fixing bug with <form data-model not set to any value

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| Tickets       | None
| License       | MIT

An oversight from #378: you should be allowed to simply say `<form data-model>` without setting `data-model` to any value.

Cheers!

Commits
-------

22ed9fb Fixing bug with <form data-model not set to any value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant