I'm creating a page that has multiple submit buttons on the same form. At first, all the buttons worked normally, but when I added a field with remote validation a strange behavior started happening.
1º Simulation (It doesn't work):
- Write an email in the email field;
- Click any button (it will send a request);
- Click another button (note that it didn't work and a request was sent from the current URL);
2º Simulation (It works):
- Write an email in the email field;
- Click any button (it will send a request);
- Click on email field;
- Click another button (note that this time the form submits the correct request of the button);
Below is the code summary that has the problem:
HTML:
<form method="post" novalidate="novalidate">
<label for="Input_Email">Email</label>
<input class="form-control" type="email" data-val="true" data-val-remote="'Email' is invalid." data-val-remote-additionalfields="*.Email" data-val-remote-type="Get" data-val-remote-url="https://jsonblob.com/api/89d8b876-54eb-11e9-8393-abf1ae9ddd11" id="Input_Email" name="Input.Email" value="">
<span class="text-danger field-validation-valid" data-valmsg-for="Input.Email" data-valmsg-replace="true"></span>
<br>
<button formaction="/MyPage/Register">Register</button>
<button formaction="/MyPage/RequestInfo">RequestInfo</button>
</form>
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.0/jquery.validate.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.11/jquery.validate.unobtrusive.js"></script>
Note: I'm using the jquery.validate and jquery-validation-unobtrusive plugins.
I wonder if this is normal behavior and how can I solve it. Thanks.