Skip to content

Commit 9cb931c

Browse files
committed
[LiveComponent] Fix form elements unsynced on load
Let's try to fix #1958
1 parent 89c7fa9 commit 9cb931c

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/LiveComponent/assets/dist/live_controller.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2671,7 +2671,11 @@ class SetValueOntoModelFieldsPlugin {
26712671
});
26722672
}
26732673
synchronizeValueOfModelFields(component) {
2674-
component.element.querySelectorAll('[data-model]').forEach((element) => {
2674+
const modelFields = [
2675+
...Array.from(component.element.querySelectorAll('[data-model]')),
2676+
...Array.from(component.element.querySelectorAll('form,input,select,textarea')),
2677+
];
2678+
modelFields.forEach((element) => {
26752679
if (!(element instanceof HTMLElement)) {
26762680
throw new Error('Invalid element using data-model.');
26772681
}

src/LiveComponent/assets/src/Component/plugins/SetValueOntoModelFieldsPlugin.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ export default class implements PluginInterface {
3030
* the "firstName" model.
3131
*/
3232
private synchronizeValueOfModelFields(component: Component): void {
33-
component.element.querySelectorAll('[data-model]').forEach((element: Element) => {
33+
const modelFields = [
34+
...Array.from(component.element.querySelectorAll('[data-model]')),
35+
...Array.from(component.element.querySelectorAll('form,input,select,textarea')),
36+
];
37+
38+
modelFields.forEach((element: Element) => {
3439
if (!(element instanceof HTMLElement)) {
3540
throw new Error('Invalid element using data-model.');
3641
}

0 commit comments

Comments
 (0)