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?
Hmm, what does your javascript look like?
Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.