Skip to content

Instantly share code, notes, and snippets.

@toropanov
Created December 11, 2015 12:38
Show Gist options
  • Save toropanov/b4bd971812ccca338a89 to your computer and use it in GitHub Desktop.
Save toropanov/b4bd971812ccca338a89 to your computer and use it in GitHub Desktop.
$('.sortable').sortable().bind 'sortupdate', ->
$(el_item).each (i, el)->
cur_index = $(el_item).index(el)
el_inputs = $(el).find('input[name]')
el_inputs.each (index, input)->
original_name = $(input).attr('name')
changed_name = original_name.replace(/\[(\d+)\]/, "[#{cur_index}]")
$(input).attr('name', changed_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment