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

Use regular button for select options #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nlopin
Copy link

@nlopin nlopin commented Aug 9, 2023

Issue

If select element is wrapped in form:

  <form>
      <select class="select-menu">
             <option value="1">Option 1</option>
             <option value="2">Option 2</option>
      </select>
  </form>

The form will be submitted every time when user selects a new value. This is undesired behaviour because only explicit submit button must send the form

Reason

<button> html tag has the type property set to submit by default

Solution

Set type to button.

button: The button has no default behavior, and does nothing when pressed by default. It can have client-side scripts listen to the element's events, which are triggered when the events occur.

MDN

`button` has the `type` attribute set to 'submit' by default, which triggers form submit.

In the case of the select, we don't want to trigger form submit when user selects an option out of it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant