如何触发具有多个选项卡但每个选项卡具有不同参数的一个表单操作(slim)

发布于 2025-01-11 09:53:12 字数 703 浏览 0 评论 0原文

我有一个带有多个选项卡的表单,如下所示:

  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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷鸟归林 2025-01-18 09:53:12

我并不是一个真正的苗条专家,因为我已经习惯了。

您需要在控制器中定义@ids。这会为每个 id 创建一个新表单,以便每个表单中都有一个名为 test 的 text_area。您可能需要调整它以将 id 放入文本区域名称中。

- @ids.each do |id|
  = form_tag({ action: "update_list", id: id }, method: put) do |form|
    .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
          .tab-pane.fade.in.active{id:"#{name}"}    
            = form.text_area :test

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 name test. you might want to tweak this to put the id into the textarea name.

- @ids.each do |id|
  = form_tag({ action: "update_list", id: id }, method: put) do |form|
    .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
          .tab-pane.fade.in.active{id:"#{name}"}    
            = form.text_area :test
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文