2013-10-17 46 views
0

如何添加到jquery填充的輸入字段的參數值?當我手工輸入內容時,一切正常。出於某種原因,動態添加的值將被忽略。我正在使用Backbone和Rails。如何將輸入字段值附加到參數?

Hamlc模板:

.modal-content 
    %form.form-signup{name: "session"} 
    .modal-header 
    .modal-body 
     .form-group 
     %input.form-control.first{name: "email", :placeholder => "#{I18n.t('email')}", type: "text", :autofocus => "", value: "[email protected]"} 
    .modal-footer 
     %input#new{type: "submit"} 

樣品片骨幹觀點:

render: -> 
    $(@el).find('input[name=email]').val('[email protected]') 

接收空參數:

Parameters: {"user"=>{"email"=>""}} 

回答

1

可以簡單地傳遞PARAMS轉移到值

= text_field_tag 'email', params[:user][:email] || '[email protected]', class: 'form-control first', placeholder: I18n.t('email') 

我正在使用rails helper來生成字段,而不是haml,通常建議這樣做:)

+0

您的解決方案在* .hamlc模板中不起作用。我會通過jQuery添加動態值然後發送它,但由於某種原因,這個值被忽略。 – luzny

相關問題