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

Form component #2023

Open
web-padawan opened this issue Nov 28, 2018 · 9 comments
Open

Form component #2023

web-padawan opened this issue Nov 28, 2018 · 9 comments

Comments

@web-padawan
Copy link
Member

Suggestion: implement the <vaadin-form> component.

Purpose

Cover a very common use case based on lacking support for native Form submission API for Custom Elements, see WICG/webcomponents#187 and also w3ctag/design-reviews#305

Use cases:

1. Get rid of the <iron-form> in the code

2. Get rid of the issues which <iron-form> has:

3. Get rid of the <iron-form> in the demos

Form submission and validation examples are currently using <iron-form> without even explaining WTF is this and why do we need it:

4. Get rid of the <iron-form> in the tests

Ultimate goal would be to drop the support for this external dependency, starting from the next major versions, e.g. in V15 (so that we reduce the vendor lock-in and promote our own stuff)

5. Provide the better UX and DX for <vaadin-form-layout> users:

6. Provide the lightweight component for using with LitElement

Ideally, the <vaadin-form> should be vanilla Custom Element, it doesn't need Polymer or LitElement dependency). This way, we can attract LitElement users who will soon feel that they miss something like that.

7. Future ideas

  • consider generating a form out of a JSON schema automatically

Implementation

The first version can be implemented by porting some parts of the <iron-form> code (and tests) and removing all the opinionated AJAX related logic.

And please, let's not make it commercial component.

@jouni
Copy link
Member

jouni commented Nov 29, 2018

Would this be more of a non-visual helper component, or could it also handle form field related functionality, like suggested in vaadin/vaadin-core#150?

Nevermind. My thoughts were stuck in form fields for some reason, and I didn’t realize this was about the whole form itself.

@heruan
Copy link
Member

heruan commented Dec 3, 2018

Probably this will also cover https://github.com/vaadin/vaadin-form-layout/issues/97 or if not, I'd suggest that 🙂

@web-padawan
Copy link
Member Author

@heruan thanks for reminder. That is a slightly different thing, but it could be attempted to done within the same scope (at least, prototyping would make sense).

@jouni
Copy link
Member

jouni commented Jan 4, 2019

A “fieldset / field group” component was in the scope for V13, but it looks like it might be a bit tight and might not make it in time.

@abdonrd
Copy link
Contributor

abdonrd commented Feb 8, 2019

Any news? I love the idea! ❤️

@Haprog
Copy link
Contributor

Haprog commented May 21, 2019

One implementation idea (which surfaced in a discussion with @tomivirkki) that might be worth prototyping was that it might be pretty simple to use a native <form> with automatically generated <input type="hidden"> elements for each form field which would be synchronized with the component values in the form (synchronized e.g. via value-changed event).

Maybe it would even be possible to implement this kind of feature in each component (a mixin maybe?) so a separate custom form element is not needed (at least for basic form submission). A component could check in connectedCallback if it is within a <form> (by traveling up the DOM crossing shadow boundaries if needed) and if so it could save a reference to the form and create an <input type="hidden"> in the form and update that whenever the component value changes. And we could use a similar strategy for enabling buttons to submit or reset a form (maybe by setting an extra property on the button).

Though we would also need to be able to prevent this from happening for components which are used as an implementation detail within another component, so that only the value of the top level component if propagated to the form.

@Legioth
Copy link
Member

Legioth commented May 22, 2019

@Haprog What you describe sounds like a polyfill for the potentially upcoming Form Participation API.

@Haprog
Copy link
Contributor

Haprog commented May 27, 2019

@Legioth I didn't actually think about that when writing the comment, but even better if this could be more of a standards based polyfill instead of custom behaviour/implementation.

Form Participation API (formdata and Form-associated custom elements) is already part of the HTML spec and implementation on they way at least in Chrome.

@vlukashov
Copy link

There is an open proposal for a Vaadin Form library to help with creating forms with Web Components. Please join the discussion at https://github.com/vaadin/proposal-for-vaadin-form

@vaadin-bot vaadin-bot transferred this issue from vaadin/vaadin-core May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants