iconicwp / WordPress-Settings-Framework

A settings framework for the WordPress settings API
MIT License
334 stars 66 forks source link

[new] Fire custom event when a group row is added #107

Closed UVLabs closed 1 year ago

UVLabs commented 1 year ago

https://github.com/iconicwp/WordPress-Settings-Framework/pull/100 brought Select2 support, but this wouldn't work when adding a new row in group, as it stands right now.

It might not be best to leave the task for the framework to check each group element to see if its a select field with multiple set, there's no need for it to do that. It can simply fire a custom trigger every time a row is added. Then in the main plugin/theme code, we can listen for that run Select2 on the respective element:

$(document).on("wpsfGroupRowAdded", function () {
   $(".select-multiple").each(function () { //select-multiple is class added in field setting array
      if (!$(this).hasClass(".select2-hidden-accessible")) {
        $(this).selectWoo();
      }
    });)
});
UVLabs commented 1 year ago

@Rahmon @davegreenwp can you take a look at this?