如何触发具有多个选项卡但每个选项卡具有不同参数的一个表单操作(slim)
我有一个带有多个选项卡的表单,如下所示:
arg = {id: @id}
= form_tag({ action: "update_list" }.merge(arg), method: put)
.form-group
ul.nav.nav-tabs
-for k,v in @list
li.nav-item class="active"
a.nav-link data-toggle="tab" href="##{k}" #{v}
div class="tab-content"
- for name in @list
div id="#{name}" class="tab-pane fade in active"
textarea.form-control name= test
可以看出,该表单封装了多个选项卡,每个选项卡都有一个文本区域,提交表单后,会发送一个 put 请求,并使用 id 作为参数。然而,每个文本区域都有不同的 id。通常在提交这样的表单时,可以为一个端点下的所有选项卡发送放置请求,并且可以为该调用使用单个参数。但是,如果每个选项卡的参数不同,它会如何工作?在这种情况下,每个文本框都有自己唯一的 ID,因此需要将多个放置请求发送到不同的端点才能提交所有选项卡。我将如何实现这一目标?本质上,用于表单的参数对于每个选项卡都是不同的。
I have a form with multiple tabs like so:
arg = {id: @id}
= form_tag({ action: "update_list" }.merge(arg), method: put)
.form-group
ul.nav.nav-tabs
-for k,v in @list
li.nav-item class="active"
a.nav-link data-toggle="tab" href="##{k}" #{v}
div class="tab-content"
- for name in @list
div id="#{name}" class="tab-pane fade in active"
textarea.form-control name= test
It can be seen that the form encapsulates multiple tabs and each tab has a text area and upon submitting of the form, a put request is sent with an id being used as an argument. However, each of the text areas have different ids. usually on submitting a form like this, a put request could be sent for all the tabs under one endpoint and a single argument could be used for that call. How would it work however if that argument is different for each tab? in this case, each textbox has its own unique id so multiple put requests would need to be sent to differing endpoints to submit all the tabs. How would I go about achieving this? essentially the argument being used for the form would be different for each tab.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我并不是一个真正的苗条专家,因为我已经习惯了。
您需要在控制器中定义
@ids
。这会为每个 id 创建一个新表单,以便每个表单中都有一个名为test
的 text_area。您可能需要调整它以将 id 放入文本区域名称中。I'm not really a slim expert, as I'm used to haml.
you'll need to define
@ids
in your controller. this creates a new form for each id, so that each form has a text_area in it with the nametest
. you might want to tweak this to put the id into the textarea name.