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

Adding the form property to the button, input, and textArea components. #1169

Closed
2 of 9 tasks
jessecanderson opened this issue Aug 30, 2022 · 5 comments
Closed
2 of 9 tasks

Comments

@jessecanderson
Copy link

Duplicate check

  • I've searched for any related issues and avoided creating a duplicate issue.

This update is for:

Component

What is the name?

button, text input and textarea

What is the nature of this update?

  • How to build this component/pattern
  • When to use this component/pattern
  • When to use something else
  • Usability guidance
  • Accessibility
  • Implementation
  • Research insights
  • Package information

What problem does this solve?

When creating a form element, a user can set an id for the form to then assign to an input, textArea, or button element to allow these elements to be in the form without them having to be in the <form></form> structure. This is useful when a user needs to have multiple forms in a specific UI but have elements for one form around elements for another form like a nested tab structure or something. The forms can be created at the top level while creating inputs throughout the page.

<div>
    <form onSubmit={handleSubmit} id="firstFormId"></form> 
    <form onSubmit={handleSubmit} id="secondFormId"></form>
    <div>
        <input form="firstFormId"></input>
        <input form="secondFormId"></input>
    </div>
    <div>
        {selectForm ?? <button form="firstFormId"></button> : <button form="secondFormId"></button>}
    </div>

For our application, we have a screen that has two forms with disproportionate elements due to a tab view that we cycle through. Using the form="id" property allows us to link the form elements to the correct form for onSubmit function calls to grab the right fields and properties. Having this in the VA design elements would allow us to maintain this feature but also use the built in functionality of the component like validation and required properties.

Additional Context

Image of the 1st form

Screen Shot 2022-08-30 at 12 51 30 PM

Image of the second form in the tab that is inside the same parent components.

Screen Shot 2022-08-30 at 12 51 39 PM

@bkjohnson
Copy link
Contributor

I'm trying to get a better understanding of the problem. Is there some reason why the elements can't be placed inside the actual form?

@jessecanderson
Copy link
Author

HTML does not allow for nested forms, and the structure of our pages requires a tab element with another form with other elements outside the tab structure in the primary form. If we had the ability to just add in the form id into the element we could create our more complex layouts with two forms that do not interact with each other.

@caw310 caw310 removed the Stretch Stretch goals label Oct 25, 2022
@bkjohnson
Copy link
Contributor

I'm still not understanding the change that is being asked of us. In your code snippet you're using <input> and <button>, so I imagine what you're describing would work with those tags. Are you relying on something like submitEvent.target.elements and expecting some components to be there? Are you using our web components, like <va-text-input>?


Based on what I know right now, the short answer is I don't think it's possible for us to do this with our web components right now because Stencil, the tool we use, doesn't support formAssociated components.

@jessecanderson
Copy link
Author

The code snippet does use the input and button, but we wanted to use the VAButton which does not support these properties. My example was to show that the base element that VAButton uses (which should be a regular button) supports the form property and we just wanted to see if we could do a passthrough of that. Make the field optional in the props and if it exists then assign it to the form prop in the base element button or input.

The VA Text Input or the VA Button don't support this form ID to pass though.

If this is not possible then that is fine, just was hoping to use the VA elements but still be able to create complex forms without nesting them (because we can't) inside the pages.

@bkjohnson
Copy link
Contributor

Sounds good. If form-associated components become an option in Stencil we may revisit this.

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

3 participants