1

こんにちは、 cocoon:https://github.com/nathanvda/cocoonと datetimepickerに問題があり:http://xdsoft.net/jqplugins/datetimepicker/ます。cocoon の新しいネストされたフィールドを追加すると、カレンダーが表示されません。javascript ファイルで cocoon after:insert イベントを使用する必要があると思いますが、すべての方法を試しましたが、うまくいきません。これは私の見解です:costs.html.haml

= simple_form_for [:partners, @car], url: wizard_path do |f|
  = f.simple_fields_for :costs do |cost|
    = render 'cost_fields', f: cost
  #links
    = link_to_add_association '+', f, :costs
  = link_to t('cars.back'), previous_wizard_path
  = f.submit t('cars.next'), class: 'btn btn-primary'

そして私の cost_fields パーシャル:

.nested-fields
  %table.table.table-striped.table-bordered.dupa
    %thead
      %th.field
        = f.association :cost_type
      %th.field  
        = f.input :netto_price
      %th.field
        = f.input :document_number

      %th.field
        = f.association :vat  

      %th.field
        = f.input :type_of_cost
      %th.field
        = f.input :date, as: :string , :input_html => { :class => 'date' } 
  = link_to_remove_association "X", f

何か案は?

4

1 に答える 1

3

この投稿がうまくいかないのは、動的に追加された要素がまだ DOM にないためです。

ネストされた単純なフィールドの前にクラスまたは ID を追加してみてください (これは既に DOM にあります)。

#container
    = f.simple_fields_for :costs do |cost|
        = render 'cost_fields', f: cost    

次に、JavaScriptファイルで:

$(document).on('ready page:change', function() {
    $('#container').on('cocoon:after-insert', function() {
       $('.datetimepicker').datetimepicker();
    })
})

また、このdatepicker gemを使用しました。これにより、ラッパー入力/カスタム日付/時刻フィールドを生成できます

= f.input :date, :as => :date_picker
于 2016-05-02T02:51:17.297 に答える