active admin nested resources form generation





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I am able to generate the required layout for nested attribute form like the below image:



form layout I want



The code for nested form:



f.inputs 'Line Item/s' do
f.has_many :payment_line_items, heading: false do |form|
table do
tr do
th 'Description'
th 'Qty'
th 'Unit Price'
th 'Amount'
end
tr do
td {form.input :description, label: false}
td {form.input :quantity, label: false}
td {form.input :unit_price, label: false}
td {form.input :amount, label: false}
end
end
end
end


When I click on 'add new payment line Item button' I get something like this image:



after adding the line item



I just want to duplicate the whole table or just the tr with the form part when I click on 'add new payment line Item' button. How can I accomplish this ?










share|improve this question































    1















    I am able to generate the required layout for nested attribute form like the below image:



    form layout I want



    The code for nested form:



    f.inputs 'Line Item/s' do
    f.has_many :payment_line_items, heading: false do |form|
    table do
    tr do
    th 'Description'
    th 'Qty'
    th 'Unit Price'
    th 'Amount'
    end
    tr do
    td {form.input :description, label: false}
    td {form.input :quantity, label: false}
    td {form.input :unit_price, label: false}
    td {form.input :amount, label: false}
    end
    end
    end
    end


    When I click on 'add new payment line Item button' I get something like this image:



    after adding the line item



    I just want to duplicate the whole table or just the tr with the form part when I click on 'add new payment line Item' button. How can I accomplish this ?










    share|improve this question



























      1












      1








      1


      1






      I am able to generate the required layout for nested attribute form like the below image:



      form layout I want



      The code for nested form:



      f.inputs 'Line Item/s' do
      f.has_many :payment_line_items, heading: false do |form|
      table do
      tr do
      th 'Description'
      th 'Qty'
      th 'Unit Price'
      th 'Amount'
      end
      tr do
      td {form.input :description, label: false}
      td {form.input :quantity, label: false}
      td {form.input :unit_price, label: false}
      td {form.input :amount, label: false}
      end
      end
      end
      end


      When I click on 'add new payment line Item button' I get something like this image:



      after adding the line item



      I just want to duplicate the whole table or just the tr with the form part when I click on 'add new payment line Item' button. How can I accomplish this ?










      share|improve this question
















      I am able to generate the required layout for nested attribute form like the below image:



      form layout I want



      The code for nested form:



      f.inputs 'Line Item/s' do
      f.has_many :payment_line_items, heading: false do |form|
      table do
      tr do
      th 'Description'
      th 'Qty'
      th 'Unit Price'
      th 'Amount'
      end
      tr do
      td {form.input :description, label: false}
      td {form.input :quantity, label: false}
      td {form.input :unit_price, label: false}
      td {form.input :amount, label: false}
      end
      end
      end
      end


      When I click on 'add new payment line Item button' I get something like this image:



      after adding the line item



      I just want to duplicate the whole table or just the tr with the form part when I click on 'add new payment line Item' button. How can I accomplish this ?







      ruby-on-rails ruby activeadmin






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 27 '18 at 3:28









      kit

      1,10431017




      1,10431017










      asked Nov 27 '18 at 1:53









      Bipin ManandharBipin Manandhar

      156




      156
























          1 Answer
          1






          active

          oldest

          votes


















          1














          I had a similar issue in one of my activeadmin projects. The fieldset element uses li elements that you can style. So check the class the form is using, and than add something like this to the end of app/assets/stylesheets/active_admin.scss. Here I assume the css class on the surrounding form is line_items. The trick is the inline-block property on the li element, you may have to fiddle with the css properties though.



          form.line_items fieldset.has_many_fields ol > li > label { display: none; }
          form.line_items fieldset.has_many_fields:first-child ol > li > label { display: block; }
          form.line_items fieldset.has_many_fields ol > li { display: inline-block; padding: 5px; width: 18%; float:left;}
          form.line_items fieldset.has_many_fields ol > li.has_many_delete { margin-top:20px; margin-left: -36px;}
          form.line_items fieldset.has_many_fields ol > li > label { width: auto; padding-right: 10px;}
          form.line_items fieldset.has_many_fields ol > li > div > label.label { width: auto; padding-right: 10px;}
          form.line_items fieldset.has_many_fields ol > li > a.has_many_remove { margin-top:20px; }
          form.line_items fieldset.has_many_fields ol > li > p.inline-errors { margin: 0.3em 0 0 0; }




          This would work but you will have to rewrite the form to:



            f.inputs 'Line Item/s' do
          f.has_many :payment_line_items, heading: false do |form|
          form.input :description, label: false
          form.input :quantity, label: false
          form.input :unit_price, label: false
          form.input :amount, label: false
          end
          end


          If you want the user to be able to destroy line items you will have to set up your assocations and the permit_params for it like so:



          In your model



          accepts_nested_attributes_for :line_items, :allow_destroy => true


          And in the activeadmin register block:



          permit_params 
          :line_items_attributes => [:id, :description, :quantity, :unit_price, :amount, :_destroy]


          Good luck!






          share|improve this answer


























          • I am not able to set the common heading as shown in the image above, like descritption, quantity, amount, unit_price

            – Bipin Manandhar
            Jan 3 at 1:47











          • Hi Bipin, my error I think. The label property on the form inputs should be omitted. And then the first 2 css rules make it so that only the first labels are retained.

            – Sjors Branderhorst
            Jan 8 at 14:22












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53491650%2factive-admin-nested-resources-form-generation%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          I had a similar issue in one of my activeadmin projects. The fieldset element uses li elements that you can style. So check the class the form is using, and than add something like this to the end of app/assets/stylesheets/active_admin.scss. Here I assume the css class on the surrounding form is line_items. The trick is the inline-block property on the li element, you may have to fiddle with the css properties though.



          form.line_items fieldset.has_many_fields ol > li > label { display: none; }
          form.line_items fieldset.has_many_fields:first-child ol > li > label { display: block; }
          form.line_items fieldset.has_many_fields ol > li { display: inline-block; padding: 5px; width: 18%; float:left;}
          form.line_items fieldset.has_many_fields ol > li.has_many_delete { margin-top:20px; margin-left: -36px;}
          form.line_items fieldset.has_many_fields ol > li > label { width: auto; padding-right: 10px;}
          form.line_items fieldset.has_many_fields ol > li > div > label.label { width: auto; padding-right: 10px;}
          form.line_items fieldset.has_many_fields ol > li > a.has_many_remove { margin-top:20px; }
          form.line_items fieldset.has_many_fields ol > li > p.inline-errors { margin: 0.3em 0 0 0; }




          This would work but you will have to rewrite the form to:



            f.inputs 'Line Item/s' do
          f.has_many :payment_line_items, heading: false do |form|
          form.input :description, label: false
          form.input :quantity, label: false
          form.input :unit_price, label: false
          form.input :amount, label: false
          end
          end


          If you want the user to be able to destroy line items you will have to set up your assocations and the permit_params for it like so:



          In your model



          accepts_nested_attributes_for :line_items, :allow_destroy => true


          And in the activeadmin register block:



          permit_params 
          :line_items_attributes => [:id, :description, :quantity, :unit_price, :amount, :_destroy]


          Good luck!






          share|improve this answer


























          • I am not able to set the common heading as shown in the image above, like descritption, quantity, amount, unit_price

            – Bipin Manandhar
            Jan 3 at 1:47











          • Hi Bipin, my error I think. The label property on the form inputs should be omitted. And then the first 2 css rules make it so that only the first labels are retained.

            – Sjors Branderhorst
            Jan 8 at 14:22
















          1














          I had a similar issue in one of my activeadmin projects. The fieldset element uses li elements that you can style. So check the class the form is using, and than add something like this to the end of app/assets/stylesheets/active_admin.scss. Here I assume the css class on the surrounding form is line_items. The trick is the inline-block property on the li element, you may have to fiddle with the css properties though.



          form.line_items fieldset.has_many_fields ol > li > label { display: none; }
          form.line_items fieldset.has_many_fields:first-child ol > li > label { display: block; }
          form.line_items fieldset.has_many_fields ol > li { display: inline-block; padding: 5px; width: 18%; float:left;}
          form.line_items fieldset.has_many_fields ol > li.has_many_delete { margin-top:20px; margin-left: -36px;}
          form.line_items fieldset.has_many_fields ol > li > label { width: auto; padding-right: 10px;}
          form.line_items fieldset.has_many_fields ol > li > div > label.label { width: auto; padding-right: 10px;}
          form.line_items fieldset.has_many_fields ol > li > a.has_many_remove { margin-top:20px; }
          form.line_items fieldset.has_many_fields ol > li > p.inline-errors { margin: 0.3em 0 0 0; }




          This would work but you will have to rewrite the form to:



            f.inputs 'Line Item/s' do
          f.has_many :payment_line_items, heading: false do |form|
          form.input :description, label: false
          form.input :quantity, label: false
          form.input :unit_price, label: false
          form.input :amount, label: false
          end
          end


          If you want the user to be able to destroy line items you will have to set up your assocations and the permit_params for it like so:



          In your model



          accepts_nested_attributes_for :line_items, :allow_destroy => true


          And in the activeadmin register block:



          permit_params 
          :line_items_attributes => [:id, :description, :quantity, :unit_price, :amount, :_destroy]


          Good luck!






          share|improve this answer


























          • I am not able to set the common heading as shown in the image above, like descritption, quantity, amount, unit_price

            – Bipin Manandhar
            Jan 3 at 1:47











          • Hi Bipin, my error I think. The label property on the form inputs should be omitted. And then the first 2 css rules make it so that only the first labels are retained.

            – Sjors Branderhorst
            Jan 8 at 14:22














          1












          1








          1







          I had a similar issue in one of my activeadmin projects. The fieldset element uses li elements that you can style. So check the class the form is using, and than add something like this to the end of app/assets/stylesheets/active_admin.scss. Here I assume the css class on the surrounding form is line_items. The trick is the inline-block property on the li element, you may have to fiddle with the css properties though.



          form.line_items fieldset.has_many_fields ol > li > label { display: none; }
          form.line_items fieldset.has_many_fields:first-child ol > li > label { display: block; }
          form.line_items fieldset.has_many_fields ol > li { display: inline-block; padding: 5px; width: 18%; float:left;}
          form.line_items fieldset.has_many_fields ol > li.has_many_delete { margin-top:20px; margin-left: -36px;}
          form.line_items fieldset.has_many_fields ol > li > label { width: auto; padding-right: 10px;}
          form.line_items fieldset.has_many_fields ol > li > div > label.label { width: auto; padding-right: 10px;}
          form.line_items fieldset.has_many_fields ol > li > a.has_many_remove { margin-top:20px; }
          form.line_items fieldset.has_many_fields ol > li > p.inline-errors { margin: 0.3em 0 0 0; }




          This would work but you will have to rewrite the form to:



            f.inputs 'Line Item/s' do
          f.has_many :payment_line_items, heading: false do |form|
          form.input :description, label: false
          form.input :quantity, label: false
          form.input :unit_price, label: false
          form.input :amount, label: false
          end
          end


          If you want the user to be able to destroy line items you will have to set up your assocations and the permit_params for it like so:



          In your model



          accepts_nested_attributes_for :line_items, :allow_destroy => true


          And in the activeadmin register block:



          permit_params 
          :line_items_attributes => [:id, :description, :quantity, :unit_price, :amount, :_destroy]


          Good luck!






          share|improve this answer















          I had a similar issue in one of my activeadmin projects. The fieldset element uses li elements that you can style. So check the class the form is using, and than add something like this to the end of app/assets/stylesheets/active_admin.scss. Here I assume the css class on the surrounding form is line_items. The trick is the inline-block property on the li element, you may have to fiddle with the css properties though.



          form.line_items fieldset.has_many_fields ol > li > label { display: none; }
          form.line_items fieldset.has_many_fields:first-child ol > li > label { display: block; }
          form.line_items fieldset.has_many_fields ol > li { display: inline-block; padding: 5px; width: 18%; float:left;}
          form.line_items fieldset.has_many_fields ol > li.has_many_delete { margin-top:20px; margin-left: -36px;}
          form.line_items fieldset.has_many_fields ol > li > label { width: auto; padding-right: 10px;}
          form.line_items fieldset.has_many_fields ol > li > div > label.label { width: auto; padding-right: 10px;}
          form.line_items fieldset.has_many_fields ol > li > a.has_many_remove { margin-top:20px; }
          form.line_items fieldset.has_many_fields ol > li > p.inline-errors { margin: 0.3em 0 0 0; }




          This would work but you will have to rewrite the form to:



            f.inputs 'Line Item/s' do
          f.has_many :payment_line_items, heading: false do |form|
          form.input :description, label: false
          form.input :quantity, label: false
          form.input :unit_price, label: false
          form.input :amount, label: false
          end
          end


          If you want the user to be able to destroy line items you will have to set up your assocations and the permit_params for it like so:



          In your model



          accepts_nested_attributes_for :line_items, :allow_destroy => true


          And in the activeadmin register block:



          permit_params 
          :line_items_attributes => [:id, :description, :quantity, :unit_price, :amount, :_destroy]


          Good luck!







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 3 '18 at 14:18

























          answered Dec 3 '18 at 14:12









          Sjors BranderhorstSjors Branderhorst

          1,3501221




          1,3501221













          • I am not able to set the common heading as shown in the image above, like descritption, quantity, amount, unit_price

            – Bipin Manandhar
            Jan 3 at 1:47











          • Hi Bipin, my error I think. The label property on the form inputs should be omitted. And then the first 2 css rules make it so that only the first labels are retained.

            – Sjors Branderhorst
            Jan 8 at 14:22



















          • I am not able to set the common heading as shown in the image above, like descritption, quantity, amount, unit_price

            – Bipin Manandhar
            Jan 3 at 1:47











          • Hi Bipin, my error I think. The label property on the form inputs should be omitted. And then the first 2 css rules make it so that only the first labels are retained.

            – Sjors Branderhorst
            Jan 8 at 14:22

















          I am not able to set the common heading as shown in the image above, like descritption, quantity, amount, unit_price

          – Bipin Manandhar
          Jan 3 at 1:47





          I am not able to set the common heading as shown in the image above, like descritption, quantity, amount, unit_price

          – Bipin Manandhar
          Jan 3 at 1:47













          Hi Bipin, my error I think. The label property on the form inputs should be omitted. And then the first 2 css rules make it so that only the first labels are retained.

          – Sjors Branderhorst
          Jan 8 at 14:22





          Hi Bipin, my error I think. The label property on the form inputs should be omitted. And then the first 2 css rules make it so that only the first labels are retained.

          – Sjors Branderhorst
          Jan 8 at 14:22




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53491650%2factive-admin-nested-resources-form-generation%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Wiesbaden

          To store a contact into the json file from server.js file using a class in NodeJS

          Marschland