Ask A Question

Notifications

You’re not receiving notifications from this thread.

field_for with index

Wouter van den Beld asked in Javascript

I have a form that uses java script and the data-attribute to do some calculations (Calx2).
to make the data-attributes unique i use the the index method that is available.

<tbody id="detail_list">
      <%= f.fields_for :detail_action_amounts, remote:true, :wrapper => false do |detail_action_amount| %>
        <tr class="fields">
           <td><%= detail_action_amount.text_field :description %></td>
           <td><%= detail_action_amount.text_field :amount :data => { :cell=> "A#{detail_action_amount.index}"} %></td>
           <td><%= detail_action_amount.text_field :factor :data => { :cell=> "B#{detail_action_amount.index}"} %></td>
           <td><%= detail_action_amount.text_field :length :data => { :cell=> "C#{detail_action_amount.index}"} %></td>
           <td><%= detail_action_amount.text_field :width, :data => { :cell=> "D#{detail_action_amount.index}"} %></td>
           <td><%= detail_action_amount.text_field :height :data => { :cell=> "E#{detail_action_amount.index}"} %></td>
           <td><%= detail_action_amount.text_field :total  :data => { :cell=> "F#{detail_action_amount.index}", :formula=> "A#{detail_action_amount.index}*(C#{detail_action_amount.index}*D#{detail_action_amount.index}*E#{detail_action_amount.index})/100*B#{detail_action_amount.index}"} %></td>
          <td><%= detail_action_amount.link_to_remove "Verwijder", :class => "btn btn-outline btn-red btn-smal btn-remove" %></td>
        </tr>
      <% end %>
    </tbody>
     <tfoot>
            <tr>
                <td colspan="6">Totaal</td>
                <td><%= f.text_field :amount, class: 'labelsize50', :data => { :cell=> "G1", :formula=> "SUM(F0:F1000)"} %></td>
                <td colspan="2"></td>
            </tr>
        </tfoot>
    </table>

This all works but when i add a field the index method adds the time in milliseconds instead of a ascending number.
is there a good and simple way to use a ascending number?

Reply

Hmm, what does your javascript look like?

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 79,047+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2023 GoRails, LLC. All rights reserved.