English 中文(简体)
如何验证Ajax表格(重选_form_tag)?
原标题:How to validate an Ajax Form Submit (remote_form_tag)?

我有亚克斯邮递等。

  - form_remote_tag :url=>mails_path,:condition=>"validate_mail()", :html => {:id=>"mailform",:method => :post, :class =>  ajax ,:style=>"padding:15px;" } do |form|
    .gimmespace 
      Naam 
      %br
      = text_field_tag :name,params[:name],:class=>"title required"
    .gimmespace 
      Telefoonnummber 
      %br
      = text_field_tag :phone,params[:phone],:size=>25,:class=>"title"
    .gimmespace 
      Mailadres 
      %br
      = text_field_tag :email,params[:email],:size=>30,:class=>"title required"
    .gimmespace 
      Onderwerp 
      %br
      = text_field_tag :subject,params[:subject],:class=>"title required"
    .gimmespace
      Boodschap 
      %br
      = text_area_tag :message,params[:message],:rows=>10,:cols=>45,:class=>"title required"
    .gimmespace
      = submit_tag "Verstuur",:id=>"mailsubmit",:class=>"sendBtn"
      %button{:onclick=>"$.fn.colorbox.close();"} Annuleer

上述法典载于HAML。 它向控制员提交一种麻风病。 我必须先确认这些领域。 因此,我尝试了几个 st子。 我读过这篇文章http://hillemania.wordpress.com/2006/09/18/rails-ajax-pre-submit-form-validation/。 此前,测试性 j印功能被击退,以验证。 这里是神圣的验证功能。

function validate_mail() {
        alert("Your Name, Email, Subject and Body Content are Required !");
        return false;

}

根据上述职能,它以任何方式退回,表格不应提交,而是以令人信服的方式提交。 如果有,请帮助。

问题回答

我认为,你希望使用<条码>:condition,而不是<条码>:选项。 与此类似:

  - form_remote_tag :url=> mails_path, :condition => "validate_mail()", ...

然后,如果您的<代码>condition功能回报不实,则提交表格。

当然,你需要修改你的<代码>validate_mail()功能,实际上检验每个表格的实地点为空白:

if ($( name ).value ==    || $( phone ).value ==    || ... ) {
  alert( Something was blank... );
  return false;
} else {
  return true;
}

我的同义词是虚伪的,这应当使你走上正轨。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签