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

Button form attribute does not render/missing after compiled in DOM #2703

Closed
liho98 opened this issue Oct 14, 2020 · 11 comments
Closed

Button form attribute does not render/missing after compiled in DOM #2703

liho98 opened this issue Oct 14, 2020 · 11 comments
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil

Comments

@liho98
Copy link

liho98 commented Oct 14, 2020

Stencil version:

 @stencil/core@ <^1.17.3>

I'm submitting a:

[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/

Current behavior:
image
image
you can see the form attribute is missing after compile in DOM.

Expected behavior:

I want the form attribute to work, so i can handle multiple form submission.

Steps to reproduce:
just add form attribute in tag

Related code:

      <Host style={{ all: "unset" }}>
        <button
          type={this.type}
          style={this.buttonStyle}
          class={`rm-button--button ${this.class}`}
          value="Submit"
          form="form1"
        >
          <slot></slot>
        </button>
      </Host>

Other information:

@ionitron-bot ionitron-bot bot added the triage label Oct 14, 2020
@liho98 liho98 changed the title Button form attribute does not render Button form attribute does not render/missing after compile in DOM Oct 14, 2020
@liho98 liho98 changed the title Button form attribute does not render/missing after compile in DOM Button form attribute does not render/missing after compiled in DOM Oct 15, 2020
@claviska claviska added bug and removed triage labels Nov 17, 2020
@claviska
Copy link
Contributor

Confirmed with a minimal component:

import { Component, h } from '@stencil/core';

@Component({
  tag: 'my-button',
  shadow: true,
})
export class AppHome {
  render() {
    return <button form="form-id-here">Submit</button>;
  }
}

The resulting markup looks like this:

CleanShot 2020-11-17 at 10 55 21@2x

@claviska
Copy link
Contributor

@adamdbradley any idea what might be causing this? I'm happy to take a stab at it if you can point me in the right direction.

@ionitron-bot ionitron-bot bot added the ionitron: stale issue This issue has not seen any activity for a long period of time label Dec 17, 2020
@ionitron-bot
Copy link

ionitron-bot bot commented Dec 17, 2020

Thanks for the issue! This issue is being closed due to inactivity. If this is still an issue with the latest version of Stencil, please create a new issue and ensure the template is fully filled out.

Thank you for using Stencil!

@ionitron-bot ionitron-bot bot closed this as completed Dec 17, 2020
@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Dec 17, 2020
@claviska claviska removed the ionitron: stale issue This issue has not seen any activity for a long period of time label Dec 17, 2020
@claviska claviska reopened this Jan 13, 2021
@ionitron-bot ionitron-bot bot added the ionitron: stale issue This issue has not seen any activity for a long period of time label Feb 12, 2021
@rwaskiewicz rwaskiewicz added Resolution: Needs Investigation This PR or Issue should be investigated from the Stencil team Feature: Renderer and removed ionitron: stale issue This issue has not seen any activity for a long period of time labels Aug 31, 2021
@ionic-team ionic-team unlocked this conversation Dec 1, 2021
@thccorni
Copy link

As a workaround I managed to use ref to get it to work:

<button
  ref={(btn) => btn?.setAttribute('form', 'form-id-here')}
>
  Submit
</button>

But it is a little ugly, I know.

@KevinCarnaille2
Copy link

FYI, still having the issue in Stencil 2.17.3 :)

@thccorni workaround is working ;)

@DavideMininni-Fincons
Copy link

Hello guys!
Yesterday I found this issue while having some trouble setting the form attribute on this component, based on Stencil.

The walkaround from @thccorni seems to work (thank you!)

If it could help, I debugged a bit the @stencil/core/internal/client/index.js;
at line 398 you could see that all params looks good and the set should be done.. but if I move one line ahead, and check for elm[memberName], it's null. I'm adding two screenshots.

form-button-bug

form-button-bug2

@rwaskiewicz
Copy link
Member

Thanks all! I've confirmed this is an issue with the minimal reproduction case above. I'm going to label this for the team to look into further

@rwaskiewicz rwaskiewicz added Bug: Validated This PR or Issue is verified to be a bug within Stencil and removed Resolution: Needs Investigation This PR or Issue should be investigated from the Stencil team labels Aug 25, 2022
@brendensoares
Copy link

brendensoares commented Sep 11, 2022

Try adding a unique key attribute and see if that keeps the element from being recreated.

The key prop is not yet well documented [1][2], but I stumbled onto it when dealing with a similar issue (integrating Stripe's Elements UI DOM mounting into a ref'd div) and it seems to have addressed the issue for me (where the div was being seemingly recreated and the referenced DOM element was lost).

PS - I'm not 100% certain of my exact issue, but I know enough to feel confident that key helped.

EDIT: this may be relevant.

@timsnadden
Copy link

This also applied to inputs

@Adamkillander96
Copy link

This issue is still present in @stencil/core@^4.7.2

We worked around it by checking after render and adding 'form' with setAttribute function.

componentDidRender() {
  if (this.form) {
    this.hostElement.querySelector('button').setAttribute('form', this.form);
  }
}

@christian-bromann
Copy link
Member

A fix for this bug has been published in Stencil v4.21.0!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil
Projects
None yet
Development

No branches or pull requests

10 participants