rough-stuff / wired-elements

Collection of custom elements that appear hand drawn. Great for wireframes or a fun look.
https://wiredjs.com
MIT License
10.43k stars 329 forks source link

input web components not sending a form #149

Open tiapnn opened 4 years ago

tiapnn commented 4 years ago

Hello there! Simple question for you seniors developers:

I seem to be unable to send a form using wiredjs web components! The form tag doesn't take the input of the input fields for some reason..

Here's a link to the webpage if you want to inspect.

Here's the code:

<form action="mailto:example@yahoo.it" method="post" enctype="text/plain">
    <wired-input type="text" id="name" placeholder="Enter name" name="name"></wired-input>
    <wired-button type="submit">Submit form</wired-button>
  </form>

Cheers

pshihn commented 4 years ago

It may not be supported at the moment out of the box. You may need to create the form data manually or perhaps add hidden fields in the form.

I will add some capability soon to make this happen automatically. Will need to do some research.

Danny-Engelman commented 4 years ago

If the element is in shadow DOM, then the creator of the element is responsible for providing values to a Form (or anything outside the element's shadowDOM)

You might also run into focus issues, which only Chredge can handle with non-standard delegateFocus for now: https://jsfiddle.net/CustomElementsExamples/9n6wtgj7/

nileshtrivedi commented 2 years ago

Shoelace solves this by handling the formdata event:

Every Shoelace component makes use of a shadow DOM to encapsulate markup, styles, and behavior. One caveat of this approach is that native <form> elements do not recognize form controls located inside a shadow root.

Shoelace solves this problem by using the formdata event, which is available in all modern browsers. This means, when a form is submitted, Shoelace form controls will automatically append their values to the FormData object that's used to submit the form. In most cases, things will "just work." However, if you're using a form serialization library, it might need to be adapted to recognize Shoelace form controls.