Guest User

Untitled

a guest
Nov 17th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. function CreateCloneCriteria(original, keepValues) {
  2. var clone = $(original).clone();
  3.  
  4. if (keepValues)
  5. {
  6. // unfortunately, the jquery library was unreliable for copying all of the children values correctly so we're doing it manually.
  7. $(clone).find('.form-control').each(function(){
  8. var cloneObject = this; // keep names straight
  9. var originalObject = $(original).find('#' + $(cloneObject).attr("id"));
  10. $(cloneObject).val($(originalObject).val());
  11. });
  12. }
  13.  
  14. // give it a unique Id
  15. var maxIdNumber = 0;
  16. $('.divRow').each(function() {
  17. var thisIdSplit = $(this).attr("id").split("divRow");
  18. var thisIdNumber = parseInt(thisIdSplit[1]);
  19. if (thisIdNumber > maxIdNumber) {
  20. maxIdNumber = thisIdNumber;
  21. }
  22. })
  23.  
  24. var newIdNumber = maxIdNumber + 1
  25. $(clone).attr("id", "divRow" + newIdNumber.toString());
  26. $(clone).children().first().attr("id", "innerDivRow" + newIdNumber.toString());
  27.  
  28. return clone;
  29. }
Add Comment
Please, Sign In to add comment