Opening a help dialog submits our settings form


Topic: Opening a help dialog submits our settings form

pixelharbor31 priority asked a week ago

The settings page has a Save button and a small help button beside a text input. Clicking help opens the dialog, but it also sends the form to our endpoint and clears the unsaved values.

Both buttons sit inside the same form. We only attach a click handler to the help button, so I am not sure where the extra submission comes from. Is there a way to keep that action separate from Save?


Igor Przybysz staff pro premium priority answered a week ago

Check the rendered type attribute on the help button. A button inside a form defaults to submit when no type is supplied, even when an application click handler opens a dialog. Give the help button type="button" and leave type="submit" on Save.

If the request still happens, please share the two buttons and the form's submit handler. Also check whether a shared handler calls requestSubmit(). Keeping submission in the form handler makes mouse clicks and Enter follow the same validation path.

https://mdbootstrap.com/docs/standard/forms/input-fields/


pixelharbor31 priority commented a week ago

The help button does not have a type. Our shared submit listener runs immediately after the click handler below, so this looks like the default action you described. Save is a separate button.

<form id="settingsForm">
  <button class="btn btn-link" id="helpButton">Help</button>
  <button class="btn btn-primary" type="submit">Save</button>
</form>
helpButton.addEventListener('click', openHelpDialog);

Igor Przybysz staff pro premium priority answered a week ago

Yes, the missing type is the cause in that markup. Add type="button" to Help. Its click handler will still run, but clicking it will no longer submit the surrounding form.

Keep Save as the submit button and retain validation in the existing submit listener. Test Enter from a text field as well, so the intended save action continues to work.

<button class="btn btn-link" id="helpButton" type="button">
  Help
</button>
<button class="btn btn-primary" type="submit">Save</button>

Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue
  • User: Pro
  • Premium support: No
  • Technology: MDB Standard
  • MDB Version: MDB5 9.3.0
  • Device: Desktop
  • Browser: Chrome
  • OS: Windows 11
  • Provided sample code: No
  • Provided link: No