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

0

cocoon にはこの機能がないようですが、リポジトリをフォークして追加しました。今のところ、次のようにできます。

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 に答える