2

我正在寻找一种方法来进行更复杂的确认,即我现在使用的那个看起来像这样:

     <%= link_to_remove_association "<i class='icon-remove-sign'></i>".html_safe, 
      p, :class => 'btn-link remove has-tooltip',
     :data => {:original_title => "Delete phone", 
     :confirm => 'Are you sure you want to delete this phone?'} %>

如果电话条目为空白,我只想避免确认对话框。

我认为'cocoon:before-remove'事件中必须有一种方法,但我无法找到它?

例如,在这样的 Coffesecript 函数中:

$(document).delegate '.phones', 'cocoon:before-remove', (e, item) ->

    tel = $(item).find('.tel .form-control')
    conf = true
    if tel.val().trim() != ''
      conf = confirm('Are you sure you want to delete this phone?')

    if conf
      $(@).data('remove-timeout', 1000)
      item.fadeOut('slow')
    else
      #stop deletion!!

    conf

有什么线索吗?

4

2 回答 2

1

实际上,您可以在处理程序中为“cocoon:before-remove”调用event.preventDefault() 。

阻止事件默认行为将取消删除操作。

于 2019-10-02T03:16:12.867 回答
0

茧似乎缺少此功能,但是我只是分叉了回购并添加了它。现在,您可以执行以下操作:

更改您的 gemfile:

gem 'cocoon', git: 'https://github.com/BroiSatse/cocoon.git'

然后修改你的处理程序:

$(document).delegate '.phones', 'cocoon:before-remove', (e, item, result) ->

  tel = $(item).find('.tel .form-control')
  conf = true
  if tel.val().trim() != ''
    conf = confirm('Are you sure you want to delete this phone?')

  if conf
    $(@).data('remove-timeout', 1000)
    item.fadeOut('slow')
  else
    result.val = false

请注意处理程序的额外参数。

于 2014-03-11T16:20:39.880 回答