【问题标题】:disable all best_in_place fields with js during AJAX request在 AJAX 请求期间使用 js 禁用所有 best_in_place 字段
【发布时间】:2013-08-02 23:34:10
【问题描述】:

我在 rails 3.2 应用程序中使用 best_in_place 2.1.0。

我有一组最好的字段,它们的值相互依赖。 因为修改一个会更改所有这些的值,所以当从其中任何一个发送 AJAX 请求时,我需要禁用所有这些的编辑。

如果您注意到,最好在等待 AJAX 请求完成时禁用一个字段。我只是想扩展它以禁用所有这些。

我尝试覆盖 onclick

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

但这没有用。有时它似乎在创建最佳现场之前被调用,但有时它似乎发生在之后。无论哪种方式,它都不适合我。

我也考虑过使用"best_in_place:activate" jQuery 触发器,但它是在BestInPlaceEditor.prototype{.. activate: } 中的this.activateForm() 之后调用的,所以它不起作用。

我不确定该怎么做。任何会动态禁用所有或选择的最佳位置字段的任何东西都对我有用。

【问题讨论】:

    标签: ruby-on-rails best-in-place


    【解决方案1】:

    如果有人仍在寻找解决方案,我会向元素添加一个类,并通过 css 取消事件:

    在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);
    });
    

    在css中:

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

    【讨论】:

      猜你喜欢
      • 2019-01-28
      • 2021-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多