【问题标题】:Problem with Ajax date select onchange valueAjax 日期选择 onchange 值的问题
【发布时间】:2011-02-18 02:01:57
【问题描述】:

当我在 date_select 上使用 AJAX 时,仅将值作为参数传递给已更改的值 但我也需要每个字段的值。

例子

日期选择

2011 年 6 月 5 日 => 更改为 2011 年 6 月 6 日,但 AJAX VALUE 仅在参数中传递值“6”。

我需要日期、月份和年份。

我的代码 风景 submit_cancellation_admin_operation_path) 做 |f| %>

  <p>Fecha de Pago:<br/><br/>
    <%= date_select("", :payment_date,  {:start_date => Time.now - 10}, {:onchange =>"#{remote_function(:url => {:controller => 'operations', :action => "update_payment_date"}, :with => "'payment_date='+value")}"}) %>
  </p>

<%  end  %>

控制器

  def cancel
    @operation        = Operation.find(params[:id])
    last_pagare       = Pagare.find(:first, :conditions => "operation_id = #{@operation.id} AND state <> 'cancelled'")
    #The condition unless is because the last_pagare could be nil if the operation is totally cancelled 
    @punitive_ammount = @operation.get_punitive(DateTime.now.to_date, last_pagare.expiration_date.to_date) unless last_pagare.nil?
  end

  def update_payment_date
    #Here I take the params 
  end 

谢谢

【问题讨论】:

  • 请问我需要如何解决这个问题

标签: ruby-on-rails


【解决方案1】:

我使用 jQuery 来解决这个问题。聆听(或阅读)您的建议的最佳解决方案(对不起,我使用谷歌翻译这句话)。

<%= date_select("", :payment_date, {:start_date => Time.now - 10}, {:onchange =>"#{remote_function(:url  => {:controller => 'operations', :action => "update_payment_date", :id=> @operation.id},
                              :with => "'payment_date_1i='+$j('#_payment_date_1i').val()+'&payment_date_2i='+$j('#_payment_date_2i').val()+'&payment_date_3i='+$j('#_payment_date_3i').val()")}"}) %>

【讨论】:

    猜你喜欢
    • 2021-06-27
    • 2011-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多