I have a simple form in a modal. Saving the form does not reload the page. Instead I simply close the modal and update the text on the page to reflect the changes made in the form.
When the user closes the modal without saving the form, I want to reset any changes they made to the form. Note the close buttons have the type “reset”:
<div class="modal-dialog">
<div class="modal-content">
<form id='myForm' onsubmit='return false;' action='someTarget'>
<div class="modal-header mb-3">
<h5 class="modal-title">My Modal</h5>
<button class="btn-close" data-bs-dismiss="modal" type="reset" aria-label="Close"></button>
</div><!-- end .modal-header -->
<div class="modal-body mt-3">
<div class="row">
<label class="col-4 col-form-label">Name</label>
<div class="col-8 col-form-label"><input class="form-control" name="name" type="text" /></div>
<div class="col-12 d-flex justify-content-end mt-4">
<button class="btn btn-label-secondary me-sm-3 me-1" data-bs-dismiss="modal" type="reset" aria-label="Close">Cancel</button>
<button class="btn btn-danger btn-animated-submit" type="submit"><span class="tf-icon bx bx-trash bx-s me-2"></span> Save</button>
</div>
</div><!-- end .row -->
</div><!-- end .modal-body -->
</form>
</div><!-- end .modal-content -->
</div><!-- end .modal-dialog -->
</div><!-- end .modal#exampleModal -->```
However, if the user makes changes to the form and saves it, only to open and close it again later - thus resetting the form - the form reverts to its original state prior to saving.
How I can change the form's "default" state when saving so that when the reset event is triggered, it reverts to the values of the last submitted state - not the one from when the page first loaded?
