Disable all best_in_place fields using js during AJAX request

I am using best_in_place 2.1.0 in rails 3.2 application.

I have a set of the best fields whose values ​​depend on each other. Since changing one changes the values ​​for all of them, I need to disable editing for all of them when an AJAX request is sent from any of them.

If you notice that it’s best in place, it already disables one field while it waits for the AJAX request to complete. I just want to expand this so that it disables them all.

I tried overriding onclick

$('.best_in_place').bind("onclick", function(e){ e.stopPropogation(); e.cancelBubble(); return false; }); 

but it didn’t work. Sometimes it seemed to be called before the creation of a better place in the field, but in other cases it seemed to occur after. In any case, this did not work for me.

I also thought about using the jQuery "best_in_place:activate" trigger, but it is called after this.activateForm() in BestInPlaceEditor.prototype{.. activate: } , so this does not work.

I'm not sure what to do. Anything that disables everything, or a choice, it will be best to use the fields dynamically, will work for me.

+4
source share
1 answer

If someone is still looking for a solution for this, I went with adding a class to the element and canceled the events via css:

in js:

 $('.best-in-place.parent-setting').on("ajax:success", function(e, t) { var enable = $(this).data('bip-value'); var childrenSettings = $(this).data('children-setting'); $('.best-in-place.'+childrenSettings).toggleClass('disabled', !enable); }); 

in css:

 .best-in-place.disabled{ opacity: .5; pointer-events: none; } 
+1
source

Source: https://habr.com/ru/post/1494827/


All Articles