【问题标题】:Rails 4 datetimepicker and cocoon gemRails 4 日期时间选择器和茧宝石
【发布时间】:2014-03-10 12:42:51
【问题描述】:

您好,cocoon 有问题:https://github.com/nathanvda/cocoon 和 datetimepicker:http://xdsoft.net/jqplugins/datetimepicker/。当我通过茧新的嵌套字段添加时,我的日历没有显示。我认为我必须在我的javascript文件中插入事件之后使用茧,但我尝试了各种方法,但这不起作用。 这是我的看法: cost.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

有什么想法吗?

【问题讨论】:

    标签: javascript jquery ruby-on-rails ruby-on-rails-4 cocoon-gem


    【解决方案1】:

    因为这个post 被忽略了,这是因为动态添加的元素还没有在 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多