blue_zinc
blue_zinc

Reputation: 2500

.click() requiring 2 clicks - jquery + QuillJS

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

Answers (1)

Nicolas
Nicolas

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

Related Questions