Newly generated ID should not be random
I've been wondering what the reasoning was to make the newId function return Date().getTime(), which is essentially random, as opposed to something useful.
newId: function() {
return new Date().getTime();
},
This is problematic for me -- I'm trying to add inline error messages for my nested resources. It would be much easier to do this if their ID used the count of their sibling fields to generate a new ID rather than something random.
For example, project[tasks_attributes][0], project[tasks_attributes][1] would be preferable to something like project[tasks_attributes][1255929127459], project[tasks_attributes][1255937127459]. These random IDs seem completely useless.
Lastly I think these would be easy to implement, as you can get .fields, and then count the nearest siblings to generate the next nested form's ID. What does everyone think?
I believe the Date.getTime() id is used to let Rails know to insert a record instead of update. I'm new to all this so I may be wrong.
Rails doesn't use the dom_id when building the nested objects, the dom_id is just presented in the view... That can't be right.
Also, if what you were saying was true, it would just look for that nested object with the ID of 1255937127459 (or whatever the time in seconds is)
I solve it using: newId: function() { return $('div.fields').length; },
I'm not sure if this $('div.fields').length idea would work if there are multiple fields_for as jQuery will count ALL the divs with class of .fields and not just the ones within that fields_for loop.