Reputation: 2500
I am using quilljs to allow users to edit a certain portion of text. However I want the editor to be fired only when a user clicks the edit button. For some reason, the edit button requires 2 clicks to execute the event. Am I missing anything?
<button id="edit" class="button" data-edit="dormant">Edit</button>
var quill = new Quill('#editor',
{
theme: 'snow',
readOnly: true,
});
$(edit).click(function () {
if (edit.data('edit') == 'dormant') {
edit.data('edit', 'active');
edit.text('Save');
quill.enable();
} else {
edit.data('edit', 'dormant');
edit.text('Edit');
quill.disable();
}
});
Upvotes: 0
Views: 94
Reputation: 8670
You need to stop the event propagation, that way, when click, it will kill the event.
$(edit).click(function (event) {
event.stopPropagation()
if (edit.data('edit') == 'dormant') {
edit.data('edit', 'active');
edit.text('Save');
quill.enable();
} else {
edit.data('edit', 'dormant');
edit.text('Edit');
quill.disable();
}
});
you can learn more on the subject here https://api.jquery.com/event.stoppropagation/
Upvotes: 1