Friday, 15 June 2012

ruby on rails - Return id from nested_attributes in javascript -



ruby on rails - Return id from nested_attributes in javascript -

i have edit view in rails number of input boxes nested_attributes.

<div class="form-group"> <%= f.fields_for :item_prices, :class => "col-sm-2" |ff|%> <%= ff.hidden_field :store_id %> <div class="col-sm-8 input_cc_size"> <label><%= ff.object.store.name %></label> <%= ff.text_field :regular_price, :class => "form-control input_cc_size_nested", :value => (number_with_precision(ff.object.regular_price, :precision => 2)) %> </div> <% end %> </div>

i dynamically in javascript when type value in first box rest take value. found reference jquery: mirror 1 text input another , trying in javascript. how can homecoming ids of nested attributes in javascript , iterate through them? if ids standard

$('#item_item_prices_attributes_0_store_id').bind('keypress blur', function() { $('#item_item_prices_attributes_1_store_id').val($(this).val()); $('#item_item_prices_attributes_2_store_id').val($(this).val()); });

but nested attributes don't know how that. in advance!

bind tag name, not id:

$('.form-group input:eq(0)').bind('keypress blur', function () { $('.form-group input:gt(0)').val($(this).val()); });

should re-create value of first input other inputs within element class form-group.

javascript ruby-on-rails nested-attributes

No comments:

Post a Comment