Programmatically turn off (uncheck) ImageEditor Lock Aspect Ratio checkbox

1 Answer 77 Views
ImageEditor
Tracy
Top achievements
Rank 1
Tracy asked on 19 Aug 2024, 11:59 PM

I've tried

$("#lockAspectRatio").data('kendoCheckBox').value(false);

and while it does uncheck the box, the aspect ratio is still locked in the background. Seems like there's a trigger/event that's firing when someone manually checks/unchecks the box and that event does not get fired when the check is set programmatically.

How do I programmatically "uncheck" the lockAspectRatio checkbox in the ImageEditor Crop toolbar?

1 Answer, 1 is accepted

Sort by
0
Ivaylo
Telerik team
answered on 20 Aug 2024, 11:27 AM

Hello Tracy,

Thank you for the information provided.

You can register a "click" event listener to the "Crop" button in the toolbar to ensure that the "lockAspectRatio" checkbox is unchecked whenever the "Crop" menu is rendered in the "DOM".

$(document).ready(() => {
        $('button[title="Crop"]').on('click', disableCheckbox);
})

 

As you can see, I am getting the element by the title attribute, because the elements in the toolbar have the same classes.

For unchecking the checkbox, I used your code and it worked correctly.

function disableCheckbox() {
        var checkbox = $("#lockAspectRatio").data('kendoCheckBox');

        checkbox.value(false);
}

Furthermore, I prepared a REPL example where you can test the code and observe how its functionality:

I hope this information was helpful.

Regards,
Ivaylo
Progress Telerik

Do you have a stake in the designеr-developer collaboration process? If so, take our survey to share your perspective and become part of this global research. You’ll be among the first to know once the results are out.
-> Start The State of Designer-Developer Collaboration Survey 2024

Tracy
Top achievements
Rank 1
commented on 20 Aug 2024, 02:26 PM

That doesn't solve the issue.

Yes, it unchecks the box. However, programmatically unchecking the box DOES NOT change the aspect ratio lock in the underlying crop control.

Manually unchecking the box DOES change the aspect ratio lock in the underlying crop control. PROGRAMMATICALLY unchecking the box DOES NOT change the aspect ratio lock in the underlying crop control.

How do I programmatically change the aspect ratio lock in the crop control?

Ivaylo
Telerik team
commented on 21 Aug 2024, 07:46 AM

Hello Tracy,

Thank you for the details provided.

Yes, that is correct. When the checkbox is unchecked, the aspect ratio does not unlock automatically; it requires manual intervention to trigger the change. You can use the "trigger" method to trigger the "change" handler of the checkbox.

function disableCheckbox() {
        var checkbox = $("#lockAspectRatio").data('kendoCheckBox');

        checkbox.value(false);

        checkbox.trigger('change');
}

In addition, I prepared a sample app where you can test the code and observe how it functions:

I hope this information was helpful.

Regards,
Ivaylo
Progress Telerik

Tags
ImageEditor
Asked by
Tracy
Top achievements
Rank 1
Answers by
Ivaylo
Telerik team
Share this question
or