public/javascripts/nested_fields.js in nested_fields-0.2.0 vs public/javascripts/nested_fields.js in nested_fields-0.2.1
- old
+ new
@@ -26,5 +26,23 @@
$('.nested_fields_has_one').live('change', function() {
var hidden_field = $(this).closest('.nested_fieldset').find('.destroy_nested_one');
$(hidden_field).val($(hidden_field).val() == 'true' ? 'false' : 'true');
$(this).closest('.nested_fieldset').find('.nested_one').toggle();
});
+
+function reposition(nested_fieldset, pos_fld) {
+ $(nested_fieldset).find('> .nested_fields').each(function(i, nested_fields) {
+ $(nested_fields).find('input[id$="' + pos_fld + '"]').val(i);
+ });
+}
+
+$('.nested_fieldset').live('nested_fields_ready', function() {
+ var pos_fld = this.getAttribute('data-positioned-by');
+
+ if (pos_fld) {
+ reposition(this, pos_fld);
+
+ if (!$(this).hasClass('ui-sortable')) {
+ $(this).sortable({update: function() { reposition(this, pos_fld); }});
+ }
+ }
+});