轨,Ajax和非Ajax按钮形式 [英] Rails form with ajax and non-ajax buttons

查看:223
本文介绍了轨,Ajax和非Ajax按钮形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的form_for有两个按钮的@object。

I have a form_for an @object with two buttons.

在第一个按钮呈现秀行动,第二个按钮再次呈现相同的形式。所以我想,后者是Ajax的处理。

While the first button renders the 'show action', the second button renders the same form again. So I'd like the latter to be ajax-handled.

是否有可能有一个非Ajax按钮和一个Ajax按钮以相同的形式还是我不得不改变策略?

Is it possible to have a non-ajax button and an ajax button in the same form or do I have to change strategy?

也许我需要用'遥控:真正的一的form_for?这样既按钮AJAX但随后,我将如何管理的第一个按钮呈现正确的显示视图

Maybe I need a form_for with 'remote: true' so that both the buttons are ajax but then, how would I manage the first button to render the proper 'show view'?

或者,也许唯一的真正的解决办法是有两种不同的形式?

Or maybe the only real solution is to have two different forms?

感谢你。

推荐答案

您可以尝试钩住按钮的onClick 事件,删除数据-remote =真正的属性,提交表单,并添加数据远程=真正的了。我不知道这是否真的是最好的方式,但它应该工作。

You could try to hook onto the buttons onClick event, remove the data-remote="true" attribute, submit the form and add data-remote="true" again. I dont know if this is really the best way but it should work.

function sendWithoutAjax() {
  $('my_form_id').removeAttr("data-remote");
  $('my_form_id').submit();
  $('my_form_id').data( "remote", "true" );
}

这样的事情...

Something like this...

这篇关于轨,Ajax和非Ajax按钮形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆