aui-toggle change event is getting triggered even when value got changed with jquery in latest AUI

Deleted user October 8, 2018

aui-toggle change event is getting triggered even when value got changed with jquery in latest AUI version.

This was not happening in the previous version of AUI (7.6.3).

When I reset the aui-toggle value with below script in change, it is triggering the change event again and it is going into a recursive infinite loop.

AJS.$('#sometoggle').on('change', function(e) {

      $(thisObj).prop("checked", !thisObj.checked);

});

1 answer

0 votes
Daz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 6, 2018

Hi Nagesh,

This appears to be the result of a change made in AUI 7.7.0; the toggle component was updated to fire the "change" event when the property was programmatically changed: https://ecosystem.atlassian.net/browse/AUI-3842

May I ask what your use-case is for updating the value of the toggle in response to its own value being updated? I'd like to understand the scenario a little more to determine whether this should be considered an undesirable behaviour in the toggle component.

If you're comfortable doing so, I would also recommend filing a bug against AUI directly: https://ecosystem.atlassian.net/secure/CreateIssue.jspa?pid=12771&issuetype=1

Cheers,

Daz

Deleted user December 6, 2018

The use-case is very simple. When we click the toggle, it opens a confirmation dialog whether we should save the change or not. If the user selects 'No', we should reset the toggle value to old value as toggle might have already changed by the time it landed in the on-change event.

lukasgotter February 12, 2019

Hi Nagesh, did you get any update or workaround?

Deleted user February 12, 2019

No update on this, there is no direct solution for this. I used below workaround to resolve my issue.

- Just make change event off before changing the value and attach the actual handler after changing the value as below.

AJS.$('#sometoggle').on('change', function(e) {

      $(thisObj).off('change');

      $(thisObj).prop("checked", !thisObj.checked);

      $(thisObj).on('change', handlerMethodRef);
});
Snir Weiss September 5, 2019

We've encountered this issue also. thanks for the workaround.

@Daz The use case is so straight-forward that you actually have an example for it in the documentation at https://docs.atlassian.com/aui/8.1.0/docs/toggle-button.html.

The WiFi example is broken, and it is stuck in an infinite loop.

Daz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 5, 2019

Thanks for resurfacing this threadm @Snir Weiss. I agree that this behaviour is problematic, so I have raised https://ecosystem.atlassian.net/browse/AUI-5071, and will follow up with the team to determine an appropriate fix version and timeframe.

Thanks for your patience.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events