|
67 | 67 | $(this).attr('data-name', name);
|
68 | 68 | });
|
69 | 69 |
|
70 |
| - $('input', copy).each(function() { |
71 |
| - var value = $(this).val(); |
72 |
| - $(this).attr('value', value); |
73 |
| - }); |
74 |
| - |
75 |
| - $('input', copy).each(function() { |
76 |
| - var value = $(this).val(); |
77 |
| - $(this).attr('value', value); |
78 |
| - }); |
79 |
| - |
80 |
| - $('textarea', copy).each(function() { |
81 |
| - var value = $(this).val(); |
82 |
| - $(this).html(value); |
83 |
| - }); |
84 |
| - |
85 | 70 | $('#modal-template')
|
86 | 71 | .compile({INDEX: index})
|
87 | 72 | .find('div.modal-body')
|
|
506 | 491 |
|
507 | 492 | row.doon();
|
508 | 493 | });
|
509 |
| - |
510 |
| - $(target).formlog() |
511 | 494 | });
|
512 | 495 |
|
513 | 496 | $(window).on('modal-cancel-click', function(e, trigger) {
|
|
532 | 515 | $(window).on('modal-save-click', function(e, trigger) {
|
533 | 516 | var modal = $(trigger).parents('div.modal').eq(0);
|
534 | 517 |
|
535 |
| - $(modal).formlog() |
536 |
| - |
537 | 518 | $('.is-error', modal).removeClass('is-error');
|
538 | 519 | $('div.error-message', modal).remove();
|
539 | 520 |
|
|
587 | 568 | .removeClass('modal-create')
|
588 | 569 | .addClass('modal-update')
|
589 | 570 | );
|
| 571 | + |
| 572 | + $('h5.modal-title', modal).html('Edit Field'); |
590 | 573 | }
|
591 | 574 |
|
592 | 575 | var row = $(trigger).parents('tr.fieldset-field-row').eq(0);
|
|
1098 | 1081 |
|
1099 | 1082 | //----------------------------//
|
1100 | 1083 | // Functions
|
| 1084 | + var $clone = $.fn.clone; |
1101 | 1085 | $.fn.extend({
|
| 1086 | + clone: function() { |
| 1087 | + //before cloning we need to set the html states for fields |
| 1088 | + //considerations |
| 1089 | + // input |
| 1090 | + // - checkbox |
| 1091 | + // - radio |
| 1092 | + // textarea |
| 1093 | + // select |
| 1094 | + $('input', this).each(function() { |
| 1095 | + $(this).attr('value', $(this).val()); |
| 1096 | + |
| 1097 | + var type = ($(this).attr('type') || 'text').toLowerCase(); |
| 1098 | + |
| 1099 | + if (type === 'radio' || type === 'checkbox') { |
| 1100 | + var checked = $(this).prop('checked'); |
| 1101 | + if (checked) { |
| 1102 | + $(this).attr('checked', 'checked'); |
| 1103 | + } else { |
| 1104 | + $(this).removeAttr('checked'); |
| 1105 | + } |
| 1106 | + } |
| 1107 | + }); |
| 1108 | + |
| 1109 | + $('textarea', this).each(function() { |
| 1110 | + $(this).html($(this).val()); |
| 1111 | + }); |
| 1112 | + |
| 1113 | + $('select', this).each(function() { |
| 1114 | + var selected = this.options[this.selectedIndex]; |
| 1115 | + $('option', this).removeAttr('selected'); |
| 1116 | + |
| 1117 | + if (selected) { |
| 1118 | + $(selected).attr('selected', 'selected'); |
| 1119 | + } |
| 1120 | + }); |
| 1121 | + |
| 1122 | + var withDataAndEvents = arguments[0] || false; |
| 1123 | + var deepWithDataAndEvents = arguments[1] || false; |
| 1124 | + var clone = $clone.call(this, withDataAndEvents, deepWithDataAndEvents); |
| 1125 | + return clone; |
| 1126 | + }, |
1102 | 1127 | compile: function(variables) {
|
1103 | 1128 | var template = this.text();
|
1104 | 1129 |
|
|
0 commit comments