I have a form, I want a loading to be displayed on the button when the form button is submitted.
I created this mode but in a simple mode.
I want to create a function that I can use in all forms, please help me, I am not fluent in jQuery?
const btnsabt = $('.btn-sabt');
btnsabt.addClass('submit-btn');
btnsabt.prop('disabled', true);
btnsabt.find('i').prop('hidden', false);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<form id="MobileUserForm" method="post">
<div class="form-group">
<input asp-for="Mobile" type="number" class="form-control" />
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-sabt">
<i class="fa fa-refresh fa-spin" hidden></i>save
</button>
</div>
</form>
2
Answers
You can try the following way:
Here is a DRYer version of Mamun’s suggestion
Not sure what the
btnsabt.addClass('submit-btn');
is for, if needed uncomment it