diff --git a/app/helpers/form_helper.rb b/app/helpers/form_helper.rb index 38624c7..b10a2b0 100644 --- a/app/helpers/form_helper.rb +++ b/app/helpers/form_helper.rb @@ -11,4 +11,8 @@ module FormHelper end end + def label_for_attr(builder, field) + (builder.object_name + field).gsub(/[\[\]]/,'_').squeeze('_') + end + end \ No newline at end of file diff --git a/app/views/apps/_fields.html.haml b/app/views/apps/_fields.html.haml index 68752e4..0a2c820 100644 --- a/app/views/apps/_fields.html.haml +++ b/app/views/apps/_fields.html.haml @@ -14,9 +14,9 @@ %div.watcher.nested %div.choose = w.radio_button :watcher_type, :user - = label_tag :watcher_type_user, 'User' + = label_tag :watcher_type_user, 'User', :for => label_for_attr(w, 'watcher_type_user') = w.radio_button :watcher_type, :email - = label_tag :watcher_type_email, 'Email Address' + = label_tag :watcher_type_email, 'Email Address', :for => label_for_attr(w, 'watcher_type_email') %div.user{:class => w.object.email.blank? ? 'choosen' : nil} = w.select :user_id, User.all.map{|u| [u.name,u.id.to_s]}, :include_blank => '-- Select a User --' %div.email{:class => w.object.email.present? ? 'choosen' : nil} diff --git a/public/javascripts/form.js b/public/javascripts/form.js index 1641849..a7b6aeb 100644 --- a/public/javascripts/form.js +++ b/public/javascripts/form.js @@ -30,15 +30,20 @@ function makeNestedItemsDestroyable(wrapper) { function appendNestedItem() { var addLink = $(this); var nestedItem = addLink.parent().find('.nested').first().clone().show(); + var timestamp = new Date(); + timestamp = timestamp.valueOf(); + nestedItem.find('input, select').each(function(){ var input = $(this); - var timestamp = new Date(); - timestamp = timestamp.valueOf(); input.attr('id', input.attr('id').replace(/([_\[])\d+([\]_])/,'$1'+timestamp+'$2')); input.attr('name', input.attr('name').replace(/([_\[])\d+([\]_])/,'$1'+timestamp+'$2')); if(input.attr('type') != 'radio') input.val(''); }); + nestedItem.find('label').each(function(){ + var label = $(this); + label.attr('for', label.attr('for').replace(/([_\[])\d+([\]_])/,'$1'+timestamp+'$2')); + }); addLink.before(nestedItem); } -- libgit2 0.21.2