Skip to content

Commit

Permalink
[LiveComponent] Fix form elements unsynced on load
Browse files Browse the repository at this point in the history
Let's try to fix #1958
  • Loading branch information
smnandre committed Nov 14, 2024
1 parent 89c7fa9 commit 9cb931c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/LiveComponent/assets/dist/live_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2671,7 +2671,11 @@ class SetValueOntoModelFieldsPlugin {
});
}
synchronizeValueOfModelFields(component) {
component.element.querySelectorAll('[data-model]').forEach((element) => {
const modelFields = [
...Array.from(component.element.querySelectorAll('[data-model]')),
...Array.from(component.element.querySelectorAll('form,input,select,textarea')),
];
modelFields.forEach((element) => {
if (!(element instanceof HTMLElement)) {
throw new Error('Invalid element using data-model.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ export default class implements PluginInterface {
* the "firstName" model.
*/
private synchronizeValueOfModelFields(component: Component): void {
component.element.querySelectorAll('[data-model]').forEach((element: Element) => {
const modelFields = [
...Array.from(component.element.querySelectorAll('[data-model]')),
...Array.from(component.element.querySelectorAll('form,input,select,textarea')),
];

modelFields.forEach((element: Element) => {
if (!(element instanceof HTMLElement)) {
throw new Error('Invalid element using data-model.');
}
Expand Down

0 comments on commit 9cb931c

Please sign in to comment.