Home > Net >  Multiple buttons for differents actions in the same Django form
Multiple buttons for differents actions in the same Django form

Time:12-17

I have a Django form where I need to include buttons to make certains actions, like fill various fields, I'm doing this with javascript scripts. The problem comes when I click that button, the form validates, like if I'm submiting the form. Are there any ways to prevent this?

CodePudding user response:

Yeah, you can easily prevent submitting the form with js.

Ex:

<button onclick="validate(event)"> Test </button>

js file:

const validate = (event) => {
   event.preventDefault();
   //do stuff
}
  • Related