Skip to content
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

Unable to unset a 'form' prop on a button with null value. #2840

Closed
LinusBorg opened this issue Dec 17, 2020 · 5 comments · Fixed by #2849
Closed

Unable to unset a 'form' prop on a button with null value. #2840

LinusBorg opened this issue Dec 17, 2020 · 5 comments · Fixed by #2849
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. 🐞 bug Something isn't working

Comments

@LinusBorg
Copy link
Member

Version

3.0.4

Reproduction link

https://jsfiddle.net/Linusborg/2fwLmu5b/

Steps to reproduce

  • Run the fiddle above.
  • check the console
  • See an error:

What is expected?

'form' attribute is being unset successfully.

What is actually happening?

Console Warning:

Failed setting prop "form" on : value null is invalid. TypeError: Cannot set property form of # which has only a getter


#1788 attempted to solve a similar problem, making Vue patch this with setAttribute instead of setting it as a DOMprop - but the added value check makes Vue fall back to a DOMprop assignment for non-string values.

Note also that setting it as an empty string is not a proper solution as this breaks the button's form property's inheritance of the form's ID it might be nested within.

So we need to use setAttribute() regardless of the type of value.

@posva
Copy link
Member

posva commented Dec 17, 2020

Do you mean we should remove the check of typeof of string? https://github.com/vuejs/vue-next/pull/1788/files#r465890830

@LinusBorg
Copy link
Member Author

LinusBorg commented Dec 17, 2020

Yep. That would mean Vue will always set it as an attribute, and setting the attribute value as null or undefined will successfully remove it, judging from my (preliminary) tests in the browser console.

We could in turn add a check for the element's type, as that attribute only exists on form elements.

@luwuer
Copy link
Contributor

luwuer commented Dec 18, 2020

The warning is because the form attr is readonly in button https://html.spec.whatwg.org/multipage/form-elements.html#the-button-element , i think this warning message should show to users .

Same as #2766 .

@LinusBorg
Copy link
Member Author

The warning should not show, it should not happen in the first place as we should set the value via setAttribute('form', ...) (which is not readonly*)

@luwuer
Copy link
Contributor

luwuer commented Dec 18, 2020

I see your point, can use setAttribute('form', ...) set attributes and attributes.form can control form attribute, sorry for it.

@LinusBorg LinusBorg added 🐞 bug Something isn't working 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. labels Dec 19, 2020
LinusBorg added a commit that referenced this issue Feb 3, 2021
… (#2849)

Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
Co-authored-by: Thorsten Lünborg <t.luenborg@googlemail.com>
@github-actions github-actions bot locked and limited conversation to collaborators Oct 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. 🐞 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants