Skip to content

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

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

Merged
merged 1 commit into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/LiveComponent/assets/src/dom_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export function getModelDirectiveFromInput(element: HTMLElement, throwOnMissing
const formElement = element.closest('form');
// require a <form data-model="*"> around elements in order to
// activate automatic "data binding" via the "name" attribute
if (formElement && formElement.dataset.model) {
const directives = parseDirectives(formElement.dataset.model);
if (formElement && ('model' in formElement.dataset)) {
const directives = parseDirectives(formElement.dataset.model || '*');
const directive = directives[0];

if (directive.args.length > 0 || directive.named.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/LiveComponent/assets/test/controller/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ describe('LiveController data-model Tests', () => {
it('falls back to using the name attribute when no data-model is present and <form data-model> is ancestor', async () => {
const test = await createTest({ color: '' }, (data: any) => `
<div ${initComponent(data)}>
<form data-model="*">
<form data-model>
<input
name="color"
value="${data.color}"
Expand Down