My function sends 2 actions after a customer makes a double click. Is it possible to modify my function to avoid it?
function createIt() {
var comment = $('textarea[name="comment"]').val();
if (!comment) {
$('#comment_error').append("Write a comment");
return false;
}
BX.ajax.runComponentAction('register:feedback',
'createIt', {
mode: 'class',
data: {
post: {
COMMENT: comment,
}
},
}).then(function (response) {
if (response.status == 'success') {
$('.formAction').hide();
$('input[name="go"]').trigger('click');
} else {
alert(response.errors);
}
});
};
My code works perfectly if a customer clicks once, but after he uses a double click, the code creates 2 records.
I updated the code.
Html part looks like this
<div class="formAction">
<form method="post" action="">
<input type="hidden" name="AJAX_CALL" value="Y">
<div class="mt-2">
<div class="crm-entity-stream-content-event-title">
Add new question
</div>
</div>
<div class="mt-2">
<textarea class="crm-entity-widget-content-textarea" name="comment" required=""></textarea>
<div id="comment_error" style="color: red;"></div>
</div>
<div class="ui-btn-container ui-btn-container-center">
<button type="button" name="add_it" id="add_it" value="" onclick="createIt()" class="ui-btn ui-btn-secondary">
ADD
</button>
</div>
</form>
</div>