PluginProbe
Repeater Fields for Gravity Forms / 3.2.0
Repeater Fields for Gravity Forms v3.2.0
3.2.0 3.1.1 3.1.0 3.0.4 3.0.3 3.0.2 3.0.1 3.0.0 2.5.1 2.5.0 2.4.6 trunk 2.0.5 2.0.9 2.1.0 2.3.2 2.3.7 2.4.1 2.4.3 2.4.4 2.4.5
← All changes | libs/wp_repeater.js +731 -383 2.1.0 → 3.2.0 View file →
@@ -1,7 +1,149 @@
1 -(function($) {
2 -"use strict";
3 - jQuery(document).ready(function($){
1 +(function ($) {
2 + "use strict";
3 + jQuery(document).ready(function ($) {
4 + jQuery(document).on('change keyup', '.gfield input, .gfield select, .gfield textarea', function (event) {
5 + gf_raw_input_change(event, this);
6 + });
7 + $("body").on('change', ".container-repeater-field .gform-grid-col--size-auto", function (e) {
8 + var self = $(this);
9 + var value = $(this).val();
10 + var input_ids = $(this).attr("name");
11 + if (input_ids === undefined) {
12 + return;
13 + }
14 + input_ids = input_ids.split("_");
15 + var input_id = input_ids[1];
16 + var form_ids = self.closest("form").attr("id");
17 + form_ids = form_ids.split("_");
18 + var form_id = form_ids[1];
19 + var field_ids = input_ids[1].split(".");
20 + if (field_ids[1] == 2) {
21 + return;
22 + }
23 + var field_id = field_ids[0];
24 + const obj = {
25 + [input_id]: value,
26 + [field_id + ".2"]: ""
27 + }
28 + var $nextSelect = $(this).closest(".ginput_container").find("#input_" + form_id + "_" + field_id + "_2_container select")
29 + $.post(gformChainedSelectData.ajaxUrl, {
30 + action: 'gform_get_next_chained_select_choices',
31 + input_id: input_id,
32 + form_id: form_id,
33 + field_id: field_id,
34 + value: obj,
35 + nonce: gformChainedSelectData.nonce
36 + }, function (response) {
37 + if (!response) {
38 + return;
39 + }
40 + var choices = $.parseJSON(response),
41 + optionsMarkup = '';
42 + $nextSelect.find('option').remove();
43 + if (choices.length <= 0) {
44 + //self.resetSelects( $select, true );
45 + } else {
46 + var hasSelectedChoice = false;
47 + $.each(choices, function (i, choice) {
48 + var selected = choice.isSelected ? 'selected="selected"' : '';
49 + if (selected) {
50 + hasSelectedChoice = true;
51 + }
52 + optionsMarkup += '<option value="' + choice.value + '"' + selected + '>' + choice.text + '</option>';
53 + });
54 + $nextSelect.show().append(optionsMarkup);
55 + // the placeholder will be selected by default, rather than removing it and re-adding, just force the noOptions option to be selected
56 + if (choices[0].noOptions) {
57 + var $noOption = $nextSelect.find('option:last-child').clone(),
58 + $nextSelects = $nextSelect.parents('span').nextAll().find('select');
59 + $nextSelects.append($noOption);
60 + $nextSelects.add($nextSelect)
61 + .addClass('gf_no_options')
62 + .find('option:last-child').prop('selected', true);
63 + //self.toggleCompleted( true );
64 + } else {
65 + $nextSelect
66 + .removeClass('gf_no_options')
67 + //.prop( 'disabled', false ).show();
68 + .toggleSelect(false, self);
69 + if (hasSelectedChoice) {
70 + $nextSelect.change();
71 + }
72 + }
73 + }
74 + //self.resizeSelects();
75 + });
76 + })
77 + gform.addFilter('gform_is_value_match', function (isMatch, formId, rule) {
78 + var check_repeater = rule['fieldId'].toString().split("-");
79 + if (check_repeater.length < 2) {
80 + return isMatch;
81 + } else {
82 + var $ = jQuery,
83 + inputId = rule['fieldId'],
84 + baseInputId = check_repeater[0],
85 + randId = check_repeater[1],
86 + baseFieldId = parseInt(baseInputId, 10),
87 + inputIndex = gformExtractInputIndex(baseInputId),
88 + isInputSpecific = inputIndex !== false,
89 + $inputs;
90 + if (isInputSpecific) {
91 + $inputs = $('#input_{0}_{1}_{2}-{3}, #choice_{0}_{1}_{2}-{3}'.gformFormat(formId, baseFieldId, inputIndex, randId));
92 + } else {
93 + $inputs = $('input[id="input_{0}_{1}-{2}"], input[id^="input_{0}_{1}_"][id$="-{2}"], input[id^="choice_{0}_{1}_"][id$="-{2}"], select#input_{0}_{1}-{2}, textarea#input_{0}_{1}-{2}'.gformFormat(formId, baseFieldId, randId));
94 + }
95 + var isCheckable = $.inArray($inputs.attr('type'), ['checkbox', 'radio']) !== -1;
96 + var isMatch = isCheckable ? gf_is_match_checkable($inputs, rule, formId, inputId) : gf_is_match_default($inputs.eq(0), rule, formId, inputId);
97 + return isMatch;
98 + }
99 + });
100 + gform.addFilter('gform_field_meta_raw_input_change', function (form, input, event) {
101 + var htmlId = input.attr('id');
102 + var fieldId = yeeaddons_gf_get_input_id_by_html_id(htmlId);
103 + var formId = gf_get_form_id_by_html_id(htmlId);
104 + if (formId !== undefined) {
105 + var check_ids = htmlId.split("-");
106 + if (check_ids.length > 1) {
107 + form = { fieldId: fieldId, formId: formId };
108 + }
109 + }
110 + return form;
111 + });
112 + function yeeaddons_gf_get_input_id_by_html_id(htmlId) {
113 + var ids = htmlId ? htmlId.split('_') : [];
114 + if (ids.length >= 3) {
115 + var type = ids[0];
116 + if (type === 'choice') {
117 + var fieldId = ids[2];
118 + var randSuffix = '';
119 + var lastPart = ids[ids.length - 1];
120 + if (lastPart && lastPart.indexOf('-') !== -1) {
121 + var parts = lastPart.split('-');
122 + randSuffix = '-' + parts[1];
123 + }
124 + return fieldId + randSuffix;
125 + } else if (type === 'input') {
126 + if (ids.length === 3) {
127 + return ids[2];
128 + } else if (ids.length >= 4) {
129 + var fieldId = ids[2];
130 + var indexPart = ids[3];
131 + return fieldId + '.' + indexPart;
132 + }
133 + }
134 + }
135 + return htmlId;
136 + }
137 + gform.addAction('gform_input_change', function (elem, formId, fieldId) {
138 + if (!window.gf_form_conditional_logic) {
139 + return;
140 + }
141 + var dependentFieldIds = rgars(gf_form_conditional_logic, [formId, 'fields', (fieldId)].join('/'));
142 + if (dependentFieldIds) {
143 + gf_apply_rules(formId, dependentFieldIds);
144 + }
145 + }, 10);
4 146 get_repeater_data_name();
5 147 var names_upload = [];
6 148 jQuery(document).on("gform_page_loaded", function (e, form_id) {
7 149 //jQuery(".gform-datepicker").datepicker('destroy');
@@ -6,121 +148,158 @@
6 148 jQuery(document).on("gform_page_loaded", function (e, form_id) {
7 149 //jQuery(".gform-datepicker").datepicker('destroy');
8 150 get_repeater_data_name();
9 151 });
10 - jQuery(document).on('gform_post_render', function(event, form_id, current_page){
11 - //jQuery(".gform-datepicker").datepicker('destroy');
152 + jQuery(document).on('gform_post_render', function (event, form_id, current_page) {
153 + //jQuery(".gform-datepicker").datepicker('destroy');
12 154 get_repeater_data_name();
13 - });
14 - var repeater_fields_htmls ={};
15 - gform.addFilter( 'gform_file_upload_status_markup', function( statusMarkup, file, size, setrings, removeFileJs, up ) {
16 - var id = up.settings.container.id;
17 - var input = $('input[name="'+id+'"]');
18 - var old_name = input.val();
19 - var new_upload = file.name;
20 - if(old_name == ""){
21 - input.val(new_upload);
22 - }else{
23 - input.val(old_name+","+new_upload);
24 - }
25 - return statusMarkup;
26 - } );
27 - gform.addFilter( 'gform_file_upload_markup', function( html, file, up, strings, imagesUrl, response ) {
28 - return html.replace("onclick", "data-onclick");;
29 - } );
30 - $("body").on("click",".gform_delete_file",function(e){
155 + });
156 + gform.addFilter('gform_file_upload_markup', function (html, file, up, strings, imagesUrl, response) {
157 + var formId = up.settings.multipart_params.form_id;
158 + var fieldId = up.settings.multipart_params.field_id;
159 + var container = $('#' + file.id).closest(".container-repeater-field");
160 + var id_rand = container.data("id");
161 + var nameAttr = 'gform_multifile_upload_' + formId + '_' + fieldId + '__' + id_rand;
162 + var repeater = container.find('input[name="' + nameAttr + '"]');
163 + if (repeater.length === 0) {
164 + repeater = container.find(".gform_multifile_upload");
165 + }
166 + var val_repeater = repeater.val();
167 + var link = response.data.uploaded_filename;
168 + if (val_repeater == "") {
169 + repeater.val(link)
170 + } else {
171 + repeater.val(val_repeater + ", " + link);
172 + }
173 + return html.replace("onclick", "data-onclick");;
174 + });
175 + if (window.gform && typeof window.gform.addFilter === 'function') {
176 + window.gform.addFilter('gform_datepicker_options_pre_init', function (options, formId, fieldId) {
177 + if (typeof fieldId === 'string' && fieldId.indexOf('-') > -1) {
178 + var originalFieldId = fieldId.split('-')[0];
179 + return window.gform.applyFilters('gform_datepicker_options_pre_init', options, formId, originalFieldId);
180 + }
181 + return options;
182 + }, 9);
183 + }
184 + var repeater_fields_htmls = {};
185 + //condition out repeater out
186 + gform.addAction('gform_post_conditional_logic_field_action1', function (formId, action, targetId, defaultValues, isInit) {
187 + if (targetId != "") {
188 + var dat_select = targetId.replace("#", '');
189 + $(".gf-field-repeater-data-html").each(function () {
190 + var html_data = $(this).val();
191 + html_data = $(html_data);
192 + if (action == "hide") {
193 + $('[data-js-reload="' + dat_select + '"]', html_data).css("display", "none");
194 + } else {
195 + $('[data-js-reload="' + dat_select + '"]', html_data).css("display", "block");
196 + }
197 + $(this).val("<div class='container-repeater-field'>" + html_data.html() + '</div>');
198 + })
199 + if (action == "hide") {
200 + $('[data-js-reload="' + dat_select + '"]').css("display", "none");
201 + } else {
202 + $('[data-js-reload="' + dat_select + '"]').css("display", "block");
203 + }
204 + }
205 + });
206 + $("body").on("click", ".gform_delete_file", function (e) {
31 207 e.preventDefault();
32 - var str =$(this).data("onclick");
208 + var str = $(this).data("onclick");
33 209 const regex = /\((.*?)\)/gm;
34 - var m="";
35 - var a="";
210 + var m = "";
211 + var a = "";
36 212 while ((m = regex.exec(str)) !== null) {
37 - // This is necessary to avoid infinite loops with zero-width matches
38 - if (m.index === regex.lastIndex) {
39 - regex.lastIndex++;
40 - }
41 - a =m[1].split(',');;
213 + // This is necessary to avoid infinite loops with zero-width matches
214 + if (m.index === regex.lastIndex) {
215 + regex.lastIndex++;
216 + }
217 + a = m[1].split(',');;
42 218 }
43 - gformDeleteUploadedFileRepeater(a[0],a[1],$(this));
219 + gformDeleteUploadedFileRepeater(a[0], a[1], $(this));
44 220 return;
45 221 })
46 - function gformDeleteUploadedFileRepeater(formId, fieldId, deleteButton){
47 - if(deleteButton.closest(".repeater-field-warp-item-data").length > 0) {
222 + function gformDeleteUploadedFileRepeater(formId, fieldId, deleteButton) {
223 + if (deleteButton.closest(".repeater-field-warp-item-data").length > 0) {
48 224 var rand_id = deleteButton.closest(".container-repeater-field").data("id");
49 225 var fileIndex = jQuery(deleteButton).parent().index();
50 - var parent = jQuery("#field_" + formId + "_" + fieldId);
226 + var parent = deleteButton.closest(".container-repeater-field").find("#field_" + formId + "_" + fieldId + "-" + rand_id);
227 + if (parent.length === 0) {
228 + parent = jQuery("#field_" + formId + "_" + fieldId);
229 + }
51 230 parent.find('input[type="file"],.validation_message,#extensions_message_' + formId + '_' + fieldId).removeClass("gform_hidden");
52 231 parent.find(".ginput_post_image_file").show();
53 232 //parent.find("input[type=\"text\"]").val('');
54 - var filesJson = jQuery('#gform_uploaded_files_' + formId).val();
55 - if(filesJson){
56 - var files = jQuery.secureEvalJSON(filesJson);
57 - if(files) {
58 - var inputName = "input_" + fieldId;
59 - var full_name = deleteButton.closest(".repeater-field-warp-item-data").find('input[name="gform_multifile_upload_'+formId+'_'+fieldId+'__'+rand_id+'"]').val();
60 - if(full_name == ""){
61 - full_name = [];
62 - }else{
63 - full_name = full_name.split(",");
64 - }
65 - var $multfile = parent.find("#gform_multifile_upload_" + formId + "_" + fieldId +"__"+rand_id );
66 - var remove_name = deleteButton.closest(".ginput_preview").find(".gfield_fileupload_filename").html();
67 - var index1 = full_name.indexOf(remove_name);
68 - if (index1 !== -1) {
69 - full_name.splice(index1, 1);
233 + var filesJson = jQuery('#gform_uploaded_files_' + formId).val();
234 + if (filesJson) {
235 + var files = jQuery.secureEvalJSON(filesJson);
236 + if (files) {
237 + var inputName = "input_" + fieldId;
238 + var full_name = deleteButton.closest(".container-repeater-field").find('input[name="gform_multifile_upload_' + formId + '_' + fieldId + '__' + rand_id + '"]').val();
239 + if (full_name == "") {
240 + full_name = [];
241 + } else {
242 + full_name = full_name.split(",");
70 243 }
71 - deleteButton.closest(".repeater-field-warp-item-data").find('input[name="gform_multifile_upload_'+formId+'_'+fieldId+'__'+rand_id+'"]').val(full_name.join(","));
72 - deleteButton.closest(".ginput_preview").remove();
73 - if( $multfile.length > 0 ) {
74 - files[inputName].splice(fileIndex, 1);
75 - var settings = $multfile.data('settings');
76 - var max = settings.gf_vars.max_files;
77 - jQuery("#" + settings.gf_vars.message_id +"__"+rand_id).html('');
78 - if(files[inputName].length < max)
79 - gfMultiFileUploader.toggleDisabled(settings, false);
80 - } else {
81 - files[inputName] = null;
82 - }
83 - jQuery('#gform_uploaded_files_' + formId).val(jQuery.toJSON(files));
84 - }
85 - }
86 - }else{
244 + var $multfile = parent.find("#gform_multifile_upload_" + formId + "_" + fieldId + "__" + rand_id);
245 + var remove_name = deleteButton.closest(".ginput_preview").find(".gfield_fileupload_filename").html();
246 + var index1 = full_name.indexOf(remove_name);
247 + if (index1 !== -1) {
248 + full_name.splice(index1, 1);
249 + }
250 + deleteButton.closest(".container-repeater-field").find('input[name="gform_multifile_upload_' + formId + '_' + fieldId + '__' + rand_id + '"]').val(full_name.join(","));
251 + deleteButton.closest(".ginput_preview").remove();
252 + if ($multfile.length > 0) {
253 + files[inputName].splice(fileIndex, 1);
254 + var settings = $multfile.data('settings');
255 + var max = settings.gf_vars.max_files;
256 + jQuery("#" + settings.gf_vars.message_id + "__" + rand_id).html('');
257 + if (files[inputName].length < max)
258 + gfMultiFileUploader.toggleDisabled(settings, false);
259 + } else {
260 + files[inputName] = null;
261 + }
262 + jQuery('#gform_uploaded_files_' + formId).val(jQuery.toJSON(files));
263 + }
264 + }
265 + } else {
87 266 var parent = jQuery("#field_" + formId + "_" + fieldId);
88 - var fileIndex = jQuery(deleteButton).parent().index();
89 - deleteButton.closest(".ginput_preview").remove();
90 - //displaying single file upload field
91 - parent.find('input[type="file"],.validation_message,#extensions_message_' + formId + '_' + fieldId).removeClass("gform_hidden");
92 - //displaying post image label
93 - parent.find(".ginput_post_image_file").show();
94 - //clearing post image meta fields
95 - parent.find("input[type=\"text\"]").val('');
96 - //removing file from uploaded meta
97 - var filesJson = jQuery('#gform_uploaded_files_' + formId).val();
98 - if(filesJson){
99 - var files = jQuery.secureEvalJSON(filesJson);
100 - if(files) {
101 - var inputName = "input_" + fieldId;
102 - var $multfile = parent.find("#gform_multifile_upload_" + formId + "_" + fieldId );
103 - if( $multfile.length > 0 ) {
104 - files[inputName].splice(fileIndex, 1);
105 - var settings = $multfile.data('settings');
106 - var max = settings.gf_vars.max_files;
107 - jQuery("#" + settings.gf_vars.message_id).html('');
108 - if(files[inputName].length < max)
109 - gfMultiFileUploader.toggleDisabled(settings, false);
110 - } else {
111 - files[inputName] = null;
112 - }
113 - jQuery('#gform_uploaded_files_' + formId).val(jQuery.toJSON(files));
114 - }
115 - }
267 + var fileIndex = jQuery(deleteButton).parent().index();
268 + deleteButton.closest(".ginput_preview").remove();
269 + //displaying single file upload field
270 + parent.find('input[type="file"],.validation_message,#extensions_message_' + formId + '_' + fieldId).removeClass("gform_hidden");
271 + //displaying post image label
272 + parent.find(".ginput_post_image_file").show();
273 + //clearing post image meta fields
274 + parent.find("input[type=\"text\"]").val('');
275 + //removing file from uploaded meta
276 + var filesJson = jQuery('#gform_uploaded_files_' + formId).val();
277 + if (filesJson) {
278 + var files = jQuery.secureEvalJSON(filesJson);
279 + if (files) {
280 + var inputName = "input_" + fieldId;
281 + var $multfile = parent.find("#gform_multifile_upload_" + formId + "_" + fieldId);
282 + if ($multfile.length > 0) {
283 + files[inputName].splice(fileIndex, 1);
284 + var settings = $multfile.data('settings');
285 + var max = settings.gf_vars.max_files;
286 + jQuery("#" + settings.gf_vars.message_id).html('');
287 + if (files[inputName].length < max)
288 + gfMultiFileUploader.toggleDisabled(settings, false);
289 + } else {
290 + files[inputName] = null;
291 + }
292 + jQuery('#gform_uploaded_files_' + formId).val(jQuery.toJSON(files));
293 + }
294 + }
116 295 }
117 296 }
118 297 var input_ids = [];
119 - function change_name_and_ids(item , field_end = null, key = null){
120 - if( key == null ){
298 + function change_name_and_ids(item, field_end = null, key = null) {
299 + if (key == null) {
121 300 var id_rand = Math.floor(Math.random() * 10000);
122 - }else{
301 + } else {
123 302 var id_rand = key;
124 303 }
125 304 var datas = JSON.parse(field_end.find(".gf-field-repeater-data").val());
126 305 var datas_ids = datas.id;
@@ -125,154 +304,307 @@
125 304 var datas = JSON.parse(field_end.find(".gf-field-repeater-data").val());
126 305 var datas_ids = datas.id;
127 306 datas_ids.push(id_rand);
128 307 datas.id = datas_ids;
129 - field_end.find(".gf-field-repeater-data").val(JSON.stringify(datas));
308 + field_end.find(".gf-field-repeater-data").val(JSON.stringify(datas));
130 309 item = $(item);
131 - item.attr("data-id",id_rand);
132 - $(".gform_fileupload_multifile",item).each(function(){
310 + item.attr("data-id", id_rand);
311 + $(".gfield_visibility_visible", item).each(function () {
133 312 var id = $(this).attr("id");
313 + $(this).attr("id", id + "-" + id_rand);
314 + $(this).attr("data-js-reload", id + "-" + id_rand);
315 + })
316 + $(".gform_fileupload_multifile", item).each(function () {
317 + var id = $(this).attr("id");
134 318 var container_item = $(this).closest(".gfield gfield--type-fileupload");
135 319 var settings = $(this).attr("data-settings");
136 320 settings = jQuery.parseJSON(settings);
137 - $.each(settings, function( index, value ) {
138 - switch(index) {
139 - case "browse_button":
140 - case "container":
141 - case "drop_element":
142 - case "filelist":
143 - settings[index] = value + "__"+id_rand;
144 - $("#"+value,item).attr("id",value + "__"+id_rand );
145 - break;
146 - case "multipart_params":
147 - //settings["multipart_params"]["field_id"] = value.field_id + "__"+id_rand;
148 - break;
149 - }
321 + $.each(settings, function (index, value) {
322 + switch (index) {
323 + case "browse_button":
324 + case "container":
325 + case "drop_element":
326 + case "filelist":
327 + settings[index] = value + "__" + id_rand;
328 + $("#" + value, item).attr("id", value + "__" + id_rand);
329 + break;
330 + case "multipart_params":
331 + //settings["multipart_params"]["field_id"] = value.field_id + "__"+id_rand;
332 + break;
333 + }
150 334 });
151 - item.append('<input type="hidden" name="'+id+'" class="agform_multifile_upload" />');
152 - $(this).attr("id",id+"__"+id_rand);
153 - $(this).attr("data-settings",JSON.stringify(settings));
154 - names_upload.push(id+"__"+id_rand);
335 + item.append('<input type="hidden" name="' + id + '" class="gform_multifile_upload" />');
336 + $(this).attr("id", id + "__" + id_rand);
337 + $(this).attr("data-settings", JSON.stringify(settings));
338 + names_upload.push(id + "__" + id_rand);
155 339 })
156 - $("input",item).each(function(){
340 + $("input", item).each(function () {
157 341 var name = $(this).attr("name");
158 - if(name == "MAX_FILE_SIZE"){
342 + if (typeof name !== 'string' || name == "MAX_FILE_SIZE") {
159 343 return;
160 344 }
161 345 var type = $(this).attr("type");
162 346 var id = $(this).attr("id");
163 347 input_ids.push(id);
164 - $(this).attr("name",name+"__"+id_rand);
165 - $(this).attr("id",id+"-"+id_rand);
166 - var value_check = localStorage.getItem(id+"-"+id_rand);
167 - if( type == "checkbox" ){
168 - if( value_check != null ){
169 - $(this).attr("checked","checked");
348 + if (name != "" && name.endsWith('[]')) {
349 + name = name.replace(/\[\]$/, '');
350 + $(this).attr("name", name + "__" + id_rand + "[]");
351 + } else {
352 + $(this).attr("name", name + "__" + id_rand);
353 + }
354 + $(this).attr("id", id + "-" + id_rand);
355 + if ($(this).hasClass('gform-datepicker') || $(this).hasClass('datepicker')) {
356 + $(this).removeAttr('data-initialized').removeData('initialized').removeClass('hasDatepicker');
357 + if (this.dataset) {
358 + delete this.dataset.initialized;
359 + delete this.dataset.toggleClickedBeforeInit;
170 360 }
171 - } else if( type == "file" ){
172 - $(this).attr("id",id+"-"+id_rand);
173 - }else if( type == "radio" ){
174 - $(this).attr("id",id+"-"+id_rand);
175 - $(this).closest("div").find("label").attr("for",id+"-"+id_rand);
361 + var $toggleBtn = $(this).siblings('.gform-datepicker-toggle');
362 + if (!$toggleBtn.length) {
363 + $toggleBtn = $(this).closest('.ginput_container_date').find('.gform-datepicker-toggle');
364 + }
365 + if ($toggleBtn.length) {
366 + $toggleBtn.attr('id', 'datepicker_toggle_' + id + '-' + id_rand);
367 + $toggleBtn.attr('aria-controls', id + '-' + id_rand);
368 + }
369 + var $kbd = $(this).siblings('#keyboardHint_' + id);
370 + if (!$kbd.length) {
371 + $kbd = $(this).closest('.ginput_container_date').find('#keyboardHint_' + id);
372 + }
373 + if ($kbd.length) {
374 + $kbd.attr('id', 'keyboardHint_' + id + '-' + id_rand);
375 + }
176 376 }
177 - else{
178 - if( value_check != null ){
377 + var value_check = localStorage.getItem(id + "-" + id_rand);
378 + if (type == "checkbox") {
379 + $(this).closest("div").find("label").attr("for", id + "-" + id_rand);
380 + if (value_check != null) {
381 + $(this).prop("checked", true).attr("checked", "checked");
382 + }
383 + } else if (type == "file") {
384 + $(this).attr("id", id + "-" + id_rand);
385 + } else if (type == "radio") {
386 + $(this).attr("id", id + "-" + id_rand);
387 + $(this).closest("div, li").find("label").attr("for", id + "-" + id_rand);
388 + var value_check = localStorage.getItem(name + "__" + id_rand);
389 + if (value_check != null) {
390 + var old_check = $(this).val();
391 + if (old_check == value_check) {
392 + $(this).prop("checked", true).attr("checked", "checked");
393 + }
394 + }
395 + }
396 + else {
397 + // ensure the field label's "for" attribute corresponds with the field's ID
398 + $(this).closest("div").parent().find("label").attr("for", id + "-" + id_rand);
399 + if (value_check != null) {
179 400 $(this).val(value_check);
180 401 }
181 402 }
182 403 })
183 - $("textarea",item).each(function(){
404 + $("textarea", item).each(function () {
184 405 var name = $(this).attr("name");
185 406 var id = $(this).attr("id");
186 - $(this).attr("name",name+"__"+id_rand);
187 - $(this).attr("id",id+"-"+id_rand);
188 - var value_check = localStorage.getItem(id+"-"+id_rand);
189 - if( value_check != null ){
407 + $(this).attr("name", name + "__" + id_rand);
408 + $(this).attr("id", id + "-" + id_rand);
409 + // ensure the field label's "for" attribute corresponds with the field's ID
410 + $(this).closest("div").parent().find("label").attr("for", id + "-" + id_rand);
411 + var value_check = localStorage.getItem(id + "-" + id_rand);
412 + if (value_check != null) {
190 413 $(this).val(value_check);
191 414 }
192 415 })
193 - $("select",item).each(function(){
416 + $("select", item).each(function () {
194 417 var name = $(this).attr("name");
195 418 var id = $(this).attr("id");
196 - $(this).attr("name",name+"__"+id_rand);
197 - $(this).attr("id",id+"-"+id_rand);
198 - var value_check = localStorage.getItem(id+"-"+id_rand);
199 - if( value_check != null ){
419 + if (name.includes("[")) {
420 + name = name.replace(/\[\]/g, '');
421 + $(this).attr("name", name + "__" + id_rand + "[]");
422 + } else {
423 + $(this).attr("name", name + "__" + id_rand);
424 + }
425 + $(this).attr("id", id + "-" + id_rand);
426 + // ensure the field label's "for" attribute corresponds with the field's ID
427 + $(this).closest("div").parent().find("label").attr("for", id + "-" + id_rand);
428 + var value_check = localStorage.getItem(id + "-" + id_rand);
429 + if (value_check != null) {
200 430 $(this).val(value_check);
201 431 }
202 432 })
203 433 return item;
204 434 }
205 - function add_repeater_data(button, key=null){
435 + function add_repeater_data(button, key = null) {
206 436 var start_field;
207 - if(key == null){
437 + if (key == null) {
208 438 var key = Math.floor(Math.random() * 10000);
209 439 }
210 440 var item = $('<div class="repeater-field-item"><div class="repeater-field-header"></div><div class="repeater-field-content"></div></div>');
211 - button.prevAll().each(function(index){
441 + button.prevAll().each(function (index) {
212 442 var item = $(this).clone();
213 - if( item.hasClass("gfield--type-repeater_start") ) {
443 + if (item.hasClass("gfield--type-repeater_start")) {
214 444 start_field = $(this);
215 445 return false;
216 446 }
217 447 })
218 - var html_field = get_repeater_data(button,key);
448 + var html_field = get_repeater_data(button, key);
219 449 var header = get_repeater_data_header(start_field);
220 450 item.find(".repeater-field-header").append(header);
221 451 item.find(".repeater-field-content").append(html_field);
222 452 button.find(".repeater-field-warp-item").append(item);
453 + item.find("input[type=radio][checked], input[type=checkbox][checked]").prop("checked", true);
223 454 update_repeater_count_header();
224 - $( "input" ).trigger( "done_load_repeater" );
225 - var j = 0;
226 - $.each( names_upload, function( key, value ) {
227 - gfMultiFileUploader.setup("#"+value);
228 - names_upload.splice(j, 1);
229 - j++;
455 + $("input").trigger("done_load_repeater");
456 + var form_ids = button.attr("id").split("_");
457 + if (yeeaddons_gf_repeater_data.pro == "ok") {
458 + var form_id = form_ids[1];
459 + if (window["gf_form_conditional_logic"] !== undefined) {
460 + if (typeof window["gf_form_conditional_logic"][form_id] !== "undefined") {
461 + var dependents = window["gf_form_conditional_logic"][form_id].dependents;
462 + var dependents_new = dependents;
463 + var dependents_new_id = [];
464 + $.each(dependents, function (key_1, value) {
465 + var datas_logic = [];
466 + $.each(value, function (key_2, value_2) {
467 + datas_logic.push(value_2 + "-" + key);
468 + })
469 + if (key_1.search("-") < 0) {
470 + dependents_new[key_1 + "-" + key] = datas_logic;
471 + dependents_new_id.push(key_1 + "-" + key);
472 + } else {
473 + dependents_new_id.push(key_1);
474 + }
475 + });
476 + var fields = window["gf_form_conditional_logic"][form_id].fields;
477 + var fields_new = fields;
478 + $.each(fields, function (key_1, value) {
479 + var datas_logic = [];
480 + $.each(value, function (key_2, value_2) {
481 + datas_logic.push(value_2 + "-" + key);
482 + })
483 + if (key_1.search("-") < 0) {
484 + fields_new[key_1 + "-" + key] = datas_logic;
485 + }
486 + });
487 + var logic = window["gf_form_conditional_logic"][form_id].logic;
488 + //console.log(window["gf_form_conditional_logic"][form_id]);
489 + var logic_new = logic;
490 + $.each(logic, function (key_1, value) {
491 + if (key_1.search("-") < 0) {
492 + // use old and add new repeater
493 + logic_new[key_1 + "-" + key] = yeeaddons_change_id_logic(value, key);
494 + } else {
495 + //da them
496 + }
497 + });
498 + var animation = window["gf_form_conditional_logic"][form_id].animation;
499 + var defaults = window["gf_form_conditional_logic"][form_id].defaults;
500 + window["gf_form_conditional_logic"][form_id] = { animation: animation, defaults: defaults, dependents: dependents_new, fields: fields_new, logic: logic_new, "ok": "ok" };
501 + gf_apply_rules(form_id, dependents_new_id, true);
502 + }
503 + }
504 + }
505 + //end logic
506 +
507 + $.each(names_upload, function (key_1, value) {
508 + if ($("#" + value).length > 0) {
509 + gfMultiFileUploader.setup("#" + value);
510 + }
230 511 });
512 + names_upload = [];
231 513 var input_mask = yeeaddons_gf_repeater_data.input_mask;
232 - $.each( input_ids, function( key_1, value_1 ) {
233 - if(value_1 in input_mask){
234 - $('#'+value_1+"-"+key).mask(input_mask[value_1]).bind('keypress', function(e){if(e.which == 13){jQuery(this).blur();} } )
514 + $.each(input_ids, function (key_1, value_1) {
515 + if (value_1 in input_mask) {
516 + $('#' + value_1 + "-" + key).mask(input_mask[value_1]).bind('keypress', function (e) { if (e.which == 13) { jQuery(this).blur(); } })
235 517 }
236 - });
237 - conditional_logic_custom(key);
518 + });
519 + conditional_logic_custom(key);
238 520 input_ids = [];
239 - $( '.gform-datepicker' ).each( function() {
240 - var $element = $( this );
241 - initSingleDatepicker( $element );
242 - $element.addClass( 'initialized' );
243 - } );
521 + $('.gform-datepicker').each(function () {
522 + var $element = $(this);
523 + if (typeof $.fn.datepicker === 'function') {
524 + // Legacy GF < 3.0: jQuery UI datepicker available
525 + if (!$element.hasClass('hasDatepicker')) {
526 + initSingleDatepicker($element);
527 + $element.addClass('initialized');
528 + }
529 + }
530 + });
531 + // GF 3.0+: Re-trigger datepicker initialization for the form
532 + // so GF's theme script loads the datepicker chunk and sets up delegation
533 + reinitGF3Datepicker(button);
244 534 }
245 - function conditional_logic_custom(rand){
535 + /**
536 + * Re-trigger GF 3.0 datepicker initialization.
537 + * GF 3.0 uses lazy-loading: the datepicker chunk is only loaded when
538 + * gform/post_render fires and .gform-datepicker elements exist in the DOM.
539 + * Since the repeater removes original fields before GF checks for them,
540 + * we need to re-dispatch the event after creating new rows.
541 + */
542 + var _gf3DatepickerTriggered = {};
543 + function reinitGF3Datepicker(el) {
544 + if (typeof $.fn.datepicker === 'function') {
545 + return; // Legacy jQuery UI datepicker is available, no need for GF 3.0 re-init
546 + }
547 + var $wrapper = el.closest('.gform_wrapper');
548 + if (!$wrapper.length) return;
549 + var formId = parseInt($wrapper.attr('id').replace('gform_wrapper_', ''));
550 + if (!formId || isNaN(formId)) return;
551 + // Only trigger once per form per page load to avoid duplicate event listeners
552 + if (_gf3DatepickerTriggered[formId]) return;
553 + _gf3DatepickerTriggered[formId] = true;
554 + // Dispatch gform/post_render so GF's theme script detects datepicker fields
555 + // and lazy-loads the accessible datepicker chunk
556 + document.dispatchEvent(new CustomEvent('gform/post_render', {
557 + detail: { formId: formId, currentPage: 1 }
558 + }));
559 + }
560 + function yeeaddons_change_id_logic(value, key) {
561 + var field_rules_inner = [];
562 + if (value && value.field && Array.isArray(value.field.rules)) { // added this line to fix js issue in add more to autofill multiple data
563 + $.each(value.field.rules, function (key_2, value_2) {
564 + if (value_2.fieldId.search("-") < 0) {
565 + var field_id_1 = value_2.fieldId + "-" + key;
566 + }
567 + field_rules_inner.push({ fieldId: field_id_1, operator: value_2.operator, value: value_2.value });
568 + })
569 + var rules = field_rules_inner;
570 + var field = { actionType: value.field.actionType, enabled: value.field.enabled, logicType: value.field.logicType, rules: rules };
571 + return { field: field, nextButton: value.nextButton, section: value.section };
572 + } else {
573 + return value;
574 + }
575 +
576 + }
577 + function conditional_logic_custom(rand) {
246 578 return;
247 - var value_check = $("#input_1_13-"+rand).val();
248 - if(value_check == "Other" || value_check == "other"){
249 - $("#input_1_14-"+rand).closest(".gfield").addClass("hidden");
250 - }else{
251 - $("#input_1_14-"+rand).closest(".gfield").removeClass("hidden");
579 + var value_check = $("#input_1_13-" + rand).val();
580 + if (value_check == "Other" || value_check == "other") {
581 + $("#input_1_14-" + rand).closest(".gfield").addClass("hidden");
582 + } else {
583 + $("#input_1_14-" + rand).closest(".gfield").removeClass("hidden");
252 584 }
253 585 }
254 - gform.addAction( 'gform_input_change', function( elem, formId, fieldId ) {
586 + gform.addAction('gform_input_change', function (elem, formId, fieldId) {
255 587 var datas = $(elem).attr("name").split("__");;
256 - if( datas.length>1 ){
588 + if (datas.length > 1) {
257 589 conditional_logic_custom(datas[1]);
258 590 }
259 - }, 10 );
260 - function get_repeater_data(step_field,key=null){
591 + }, 10);
592 + function get_repeater_data(step_field, key = null) {
261 593 var data_html = step_field.find(".gf-field-repeater-data-html").val();
262 - if(data_html == ""){
594 + if (data_html == "") {
263 595 data_html = step_field.find(".gf-field-repeater-data-html").attr('value');
264 - }
265 - var html_step = change_name_and_ids(data_html,step_field,key);
596 + }
597 + var html_step = change_name_and_ids(data_html, step_field, key);
266 598 return html_step;
267 599 }
268 - function get_repeater_data_name(){
600 + function get_repeater_data_name() {
269 601 var i = 1;
270 - $(".gfield--type-repeater_start").each(function(){
271 - if($(this).data("installed") == "installed"){
602 + $(".gfield--type-repeater_start").each(function () {
603 + if ($(this).data("installed") == "installed") {
272 604 return;
273 605 }
274 - $(this).data("installed","installed");
606 + $(this).data("installed", "installed");
275 607 $(this).addClass("installed");
276 608 var html_step = $("<div class='container-repeater-field'></div>");
277 609 var names = [];
278 610 var step_field = "";
@@ -277,187 +609,196 @@
277 609 var names = [];
278 610 var step_field = "";
279 611 var elements = $(this).nextAll();
280 612 var value = "";
281 - elements.each(function(index){
282 - var item = $(this).clone();
283 - if( item.hasClass("gfield--type-repeater_end") ) {
284 - $(this).attr("data-id",i);
285 - value = $(this).find("input").val();
286 - if(value == ""){
287 - value = $(this).find("input").attr("value");
288 - }
289 - step_field = $(this);
290 - $(this).find(".gf-field-repeater-data").val(JSON.stringify({"count":1,"fields":names,"id":[]}));
291 - $(this).find(".gf-field-repeater-data").attr("value",JSON.stringify({"count":1,"fields":names,"id":[]}));
292 - return false;
613 + elements.each(function (index) {
614 + var item = $(this).clone();
615 + if (item.hasClass("gfield--type-repeater_end")) {
616 + $(this).attr("data-id", i);
617 + value = $(this).find("input").val();
618 + if (value == "") {
619 + value = $(this).find("input").attr("value");
293 620 }
294 - $(this).remove();
295 - html_step.append(item);
296 - var check_name = null;
297 - if(item.find(".ginput_container_fileupload").length > 0 ){
298 - var name = item.find("input[type=file]").attr("name");
299 - if( name === undefined ){
300 - name = item[0].id;
301 - name = name.split("field");
302 - names.push("gform_multifile_upload"+name[1]);
303 - }else{
304 - names.push(item.find("input[type=file]").attr("name"));
305 - }
306 - }else{
307 - if( item.find("input").attr("name") ) {
308 - names.push(item.find("input").attr("name"));
309 - }else if( item.find("textarea").attr("name") ){
310 - names.push(item.find("textarea").attr("name"));
311 - }else if( item.find("select").attr("name") ){
312 - names.push(item.find("select").attr("name"));
313 - }else{
314 - var type = item.find("input").attr("type");
315 - names.push(item.find("input").attr("name"));
316 - }
621 + step_field = $(this);
622 + $(this).find(".gf-field-repeater-data").val(JSON.stringify({ "count": 1, "fields": names, "id": [] }));
623 + $(this).find(".gf-field-repeater-data").attr("value", JSON.stringify({ "count": 1, "fields": names, "id": [] }));
624 + return false;
625 + }
626 + $(this).remove();
627 + html_step.append(item);
628 + var check_name = null;
629 + if (item.find(".ginput_container_fileupload").length > 0) {
630 + var name = item.find("input[type=file]").attr("name");
631 + if (name === undefined) {
632 + name = item[0].id;
633 + name = name.split("field");
634 + names.push("gform_multifile_upload" + name[1]);
635 + } else {
636 + names.push(item.find("input[type=file]").attr("name"));
317 637 }
638 + } else {
639 + if (item.find("input").attr("name")) {
640 + var custom_n = item.find("input").attr("name");
641 + custom_n = custom_n.replace(/\[\]$/, '');
642 + names.push(custom_n);
643 + } else if (item.find("textarea").attr("name")) {
644 + names.push(item.find("textarea").attr("name"));
645 + } else if (item.find("select").attr("name")) {
646 + names.push(item.find("select").attr("name"));
647 + } else {
648 + var type = item.find("input").attr("type");
649 + names.push(item.find("input").attr("name"));
650 + }
651 + }
318 652 })
319 - var text_html = "<div class='container-repeater-field'>"+html_step.html()+"</div>";
653 + var text_html = "<div class='container-repeater-field'>" + html_step.html() + "</div>";
320 654 step_field.find(".gf-field-repeater-data-html").val(text_html);
321 - step_field.find(".gf-field-repeater-data-html").attr("value",text_html);
655 + step_field.find(".gf-field-repeater-data-html").attr("value", text_html);
322 656 var initial_rows = 1;
323 657 initial_rows = step_field.find(".repeater-field-warp-item-data").data("initial_rows");
324 - var initial_rows_map_field = step_field.find(".repeater-field-warp-item-data").data("initial_rows_map");
325 - var initial_rows_map_number = $("#"+initial_rows_map_field).val();
326 - if(initial_rows_map_number == ""){
327 - initial_rows_map_number = $("#"+initial_rows_map_field).attr("value");
328 - }
329 - if(initial_rows_map_number > 0){
330 - $("#"+initial_rows_map_field).attr("data-repeater",step_field.find(".repeater-field-warp-item-data").data("map_id"));
331 - $("#"+initial_rows_map_field).attr("repeater_initial_rows","ok");
658 + var initial_rows_map_field_check = step_field.find(".repeater-field-warp-item-data").data("initial_rows_map_check");
659 + if (initial_rows_map_field_check != "" && initial_rows_map_field_check !== undefined) {
660 + var initial_rows_map_field = step_field.find(".repeater-field-warp-item-data").data("initial_rows_map");
661 + var initial_rows_map_number = $("#" + initial_rows_map_field).val();
662 + if (initial_rows_map_number == "") {
663 + initial_rows_map_number = $("#" + initial_rows_map_field).attr("value");
664 + }
665 + if (initial_rows_map_number == "") {
666 + initial_rows_map_number = 0;
667 + }
668 + $("#" + initial_rows_map_field).attr("data-repeater", step_field.find(".repeater-field-warp-item-data").data("map_id"));
669 + $("#" + initial_rows_map_field).attr("repeater_initial_rows", "ok");
332 670 initial_rows = initial_rows_map_number;
333 671 step_field.find(".gf-repeater-field-button-add").addClass("hidden");
334 672 step_field.addClass("repeater-remove-toolbar");
335 673 }
336 - if( value != "" ){
674 + if (initial_rows === undefined || initial_rows === "") {
675 + initial_rows = 1;
676 + }
677 + if (value != "") {
337 678 value = JSON.parse(value);
338 679 initial_rows = value.count;
339 680 var data_arr_ids = value.id;
340 - setTimeout(function() {
341 - for (var j = 0; j < initial_rows; j++) {
342 - add_repeater_data(step_field.closest(".gfield--type-repeater_end"),data_arr_ids[j]);
343 - }
344 - }, 100);
345 - }else{
346 - setTimeout(function() {
347 - for (var j = 0; j < initial_rows; j++) {
681 + setTimeout(function () {
682 + for (var j = 0; j < initial_rows; j++) {
683 + add_repeater_data(step_field.closest(".gfield--type-repeater_end"), data_arr_ids[j]);
684 + }
685 + }, 100);
686 + } else {
687 + setTimeout(function () {
688 + for (var j = 0; j < initial_rows; j++) {
348 689 add_repeater_data(step_field.closest(".gfield--type-repeater_end"));
349 690 }
350 - }, 100);
691 + }, 100);
351 692 }
352 693 i++;
353 694 })
354 695 }
355 - $("body").on("change","[repeater_initial_rows='ok']",function (e){
696 + $("body").on("change", "[repeater_initial_rows='ok']", function (e) {
356 697 var repeater_id = $(this).data("repeater");
357 - $("#"+repeater_id).find(".repeater-field-item").remove();
698 + $("#" + repeater_id).find(".repeater-field-item").remove();
358 699 var number = $(this).val();
359 - if(number == ""){
700 + if (number == "") {
360 701 number = $(this).attr("value");
361 702 }
362 703 for (let i = 0; i < number; i++) {
363 - $("#"+repeater_id).find(".gf-repeater-field-button-add").click();
364 - }
704 + $("#" + repeater_id).find(".gf-repeater-field-button-add").click();
705 + }
365 706 })
366 - function get_repeater_data_header(start_field){
707 + function get_repeater_data_header(start_field) {
367 708 var html_step = start_field.find(".repeater-field-header-data").val();
368 - if(html_step == ""){
709 + if (html_step == "") {
369 710 html_step = start_field.find(".repeater-field-header-data").attr("value");
370 711 }
371 712 return html_step;
372 713 }
373 - function update_repeater_count_header(){
374 - $(".gfield--type-repeater_end").each(function(){
375 - var i = 1;
376 - $(".repeater-field-item",$(this)).each(function(){
377 - $(this).find(".repeater-field-header-count").html(i);
378 - i++;
379 - })
380 - var data_js = $(this).find(".gf-field-repeater-data").val();
381 - if(data_js == ""){
382 - $(this).find(".gf-field-repeater-data").attr("value");
383 - }
384 - var datas = JSON.parse(data_js);
385 - datas.count = i-1;
386 - $(this).find(".gf-field-repeater-data").val(JSON.stringify(datas));
387 - $(this).find(".gf-field-repeater-data").attr("value",JSON.stringify(datas));
714 + function update_repeater_count_header() {
715 + $(".gfield--type-repeater_end").each(function () {
716 + var i = 1;
717 + $(".repeater-field-item", $(this)).each(function () {
718 + $(this).find(".repeater-field-header-count").html(i);
719 + i++;
720 + })
721 + var data_js = $(this).find(".gf-field-repeater-data").val();
722 + if (data_js == "") {
723 + $(this).find(".gf-field-repeater-data").attr("value");
724 + }
725 + var datas = JSON.parse(data_js);
726 + datas.count = i - 1;
727 + $(this).find(".gf-field-repeater-data").val(JSON.stringify(datas));
728 + $(this).find(".gf-field-repeater-data").attr("value", JSON.stringify(datas));
388 729 });
389 730 }
390 - function check_max_row(step_field){
731 + function check_max_row(step_field) {
391 732 var max = step_field.find(".repeater-field-warp-item-data").data("limit");
392 - var number_item = $('.repeater-field-item',step_field).length;
393 - if( number_item >= max ){
733 + var number_item = $('.repeater-field-item', step_field).length;
734 + if (number_item >= max) {
394 735 return false;
395 - }else{
736 + } else {
396 737 return true;
397 738 }
398 739 }
399 - function check_min_row(step_field){
740 + function check_min_row(step_field) {
400 741 var min = step_field.find(".repeater-field-warp-item-data").data("initial_rows");
401 - var number_item = $('.repeater-field-item',step_field).length;
402 - if( number_item <= min ){
742 + var number_item = $('.repeater-field-item', step_field).length;
743 + if (number_item <= min) {
403 744 return false;
404 - }else{
745 + } else {
405 746 return true;
406 747 }
407 748 }
408 749 function removeAR(arr) {
409 - var what, a = arguments, L = a.length, ax;
410 - while (L > 1 && arr.length) {
411 - what = a[--L];
412 - while ((ax= arr.indexOf(what)) !== -1) {
413 - arr.splice(ax, 1);
414 - }
415 - }
416 - return arr;
750 + var what, a = arguments, L = a.length, ax;
751 + while (L > 1 && arr.length) {
752 + what = a[--L];
753 + while ((ax = arr.indexOf(what)) !== -1) {
754 + arr.splice(ax, 1);
755 + }
756 + }
757 + return arr;
417 758 }
418 - $("body").on("click",".gf-repeater-field-button-add",function(e){
419 - e.preventDefault();
420 - if( check_max_row($(this).closest(".gfield--type-repeater_end")) ){
421 - add_repeater_data($(this).closest(".gfield--type-repeater_end"));
422 - }else{
423 - $(this).addClass('hidden');
424 - }
425 - })
426 - $("body").on("click",".repeater-field-header-acctions-toogle",function(e){
427 - e.preventDefault();
428 - if( $(this).hasClass("icon-down-open")){
429 - $(this).removeClass("icon-down-open");
430 - $(this).addClass("icon-up-open");
431 - }else{
432 - $(this).addClass("icon-down-open");
433 - $(this).removeClass("icon-up-open");
434 - }
435 - $(this).closest(".repeater-field-item").find(".repeater-field-content").slideToggle("slow");
436 - $(this).closest(".repeater-field-item").find(".repeater-field-header").toggleClass('repeater-content-show');
437 - })
438 - $("body").on("click",".repeater-field-header-acctions-remove",function(e){
439 - e.preventDefault();
440 - $(this).closest(".gfield--type-repeater_end").find(".gf-repeater-field-button-add").removeClass('hidden');
441 - if( check_min_row($(this).closest(".gfield--type-repeater_end")) ){
442 - var id = $(this).closest(".repeater-field-item").find(".container-repeater-field").data("id");
759 + $("body").on("click", ".gf-repeater-field-button-add", function (e) {
760 + e.preventDefault();
761 + if (check_max_row($(this).closest(".gfield--type-repeater_end"))) {
762 + add_repeater_data($(this).closest(".gfield--type-repeater_end"));
763 + } else {
764 + $(this).addClass('hidden');
765 + }
766 + })
767 + $("body").on("click", ".repeater-field-header-acctions-toogle", function (e) {
768 + e.preventDefault();
769 + if ($(this).hasClass("icon-down-open")) {
770 + $(this).removeClass("icon-down-open");
771 + $(this).addClass("icon-up-open");
772 + } else {
773 + $(this).addClass("icon-down-open");
774 + $(this).removeClass("icon-up-open");
775 + }
776 + $(this).closest(".repeater-field-item").find(".repeater-field-content").slideToggle("slow");
777 + $(this).closest(".repeater-field-item").find(".repeater-field-header").toggleClass('repeater-content-show');
778 + })
779 + $("body").on("click", ".repeater-field-header-acctions-remove", function (e) {
780 + e.preventDefault();
781 + $(this).closest(".gfield--type-repeater_end").find(".gf-repeater-field-button-add").removeClass('hidden');
782 + if (check_min_row($(this).closest(".gfield--type-repeater_end"))) {
783 + var id = $(this).closest(".repeater-field-item").find(".container-repeater-field").data("id");
443 784 var data_js = $(this).closest(".gfield--type-repeater_end").find(".gf-field-repeater-data").val();
444 - if(data_js == ""){
785 + if (data_js == "") {
445 786 data_js = $(this).closest(".gfield--type-repeater_end").find(".gf-field-repeater-data").attr("value");
446 787 }
447 - var datas = JSON.parse(data_js);
788 + var datas = JSON.parse(data_js);
448 789 var datas_ids = datas.id;
449 - datas_ids = removeAR(datas_ids,id);
790 + datas_ids = removeAR(datas_ids, id);
450 791 datas.id = datas_ids;
451 792 $(this).closest(".gfield--type-repeater_end").find(".gf-field-repeater-data").val(JSON.stringify(datas));
452 - $(this).closest(".gfield--type-repeater_end").find(".gf-field-repeater-data").attr("value",JSON.stringify(datas));
453 - $(this).closest(".repeater-field-item").remove();
454 - }else{
455 - }
456 - update_repeater_count_header();
457 - })
458 - //date pick
459 - function getDatepickerI18n() {
793 + $(this).closest(".gfield--type-repeater_end").find(".gf-field-repeater-data").attr("value", JSON.stringify(datas));
794 + $(this).closest(".repeater-field-item").remove();
795 + } else {
796 + }
797 + update_repeater_count_header();
798 + })
799 + //date pick
800 + function getDatepickerI18n() {
460 801 var i18n = gform_i18n.datepicker;
461 802 return {
462 803 dayNamesMin: [
463 804 i18n.days.sunday,
@@ -505,16 +846,16 @@
505 846 * beforeShow: (function(*, *): boolean),
506 847 * showOtherMonths: boolean
507 848 * }}
508 849 */
509 - function getDatepickerBaseOptions( $element ) {
850 + function getDatepickerBaseOptions($element) {
510 851 var i18n = getDatepickerI18n();
511 - var isThemeDatepicker = $element.closest( '.gform_wrapper' ).length > 0;
512 - var isPreview = $( '#preview_form_container' ).length > 0;
852 + var isThemeDatepicker = $element.closest('.gform_wrapper').length > 0;
853 + var isPreview = $('#preview_form_container').length > 0;
513 854 var isRTL = window.getComputedStyle($element[0], null).getPropertyValue('direction') === 'rtl';
514 - var formTheme = isThemeDatepicker ? $element.closest( '.gform_wrapper' ).data( 'form-theme' ) : 'gravity-theme';
515 - var formId = isThemeDatepicker ? $element.closest( '.gform_wrapper' ).attr( 'id' ).replace( 'gform_wrapper_', '' ) : '';
516 - var formPageInstance = isThemeDatepicker ? $element.closest( '.gform_wrapper' ).attr( 'data-form-index' ) : '';
855 + var formTheme = isThemeDatepicker ? $element.closest('.gform_wrapper').data('form-theme') : 'gravity-theme';
856 + var formId = isThemeDatepicker ? $element.closest('.gform_wrapper').attr('id').replace('gform_wrapper_', '') : '';
857 + var formPageInstance = isThemeDatepicker ? $element.closest('.gform_wrapper').attr('data-form-index') : '';
517 858 return {
518 859 yearRange: '-100:+20',
519 860 showOn: 'focus',
520 861 dateFormat: 'mm/dd/yy',
@@ -525,47 +866,47 @@
525 866 changeYear: true,
526 867 isRTL: isRTL,
527 868 showOtherMonths: isThemeDatepicker,
528 869 suppressDatePicker: false,
529 - onClose: function() {
870 + onClose: function () {
530 871 var self = this;
531 872 $element.focus();
532 873 this.suppressDatePicker = true;
533 - setTimeout( function() {
874 + setTimeout(function () {
534 875 self.suppressDatePicker = false;
535 - }, 200 );
876 + }, 200);
536 877 },
537 - beforeShow: function( input, inst ) {
878 + beforeShow: function (input, inst) {
538 879 // Remove any classes that were added before as it could have been added to a different datepicker.
539 - inst.dpDiv[0].classList.remove( 'gform-theme-datepicker' );
540 - inst.dpDiv[0].classList.remove( 'gravity-theme' );
541 - inst.dpDiv[0].classList.remove( 'gform-theme' );
542 - inst.dpDiv[0].classList.remove( 'gform-legacy-datepicker' );
543 - inst.dpDiv[0].classList.remove( 'gform-theme--framework' );
544 - inst.dpDiv[0].classList.remove( 'gform-theme--foundation' );
545 - inst.dpDiv[0].classList.remove( 'gform-theme--orbital' );
546 - if ( isThemeDatepicker ) {
547 - inst.dpDiv[ 0 ].classList.add( 'gform-theme-datepicker' );
548 - $( inst.dpDiv[ 0 ] ).attr( 'data-parent-form', formId + '_' + formPageInstance );
880 + inst.dpDiv[0].classList.remove('gform-theme-datepicker');
881 + inst.dpDiv[0].classList.remove('gravity-theme');
882 + inst.dpDiv[0].classList.remove('gform-theme');
883 + inst.dpDiv[0].classList.remove('gform-legacy-datepicker');
884 + inst.dpDiv[0].classList.remove('gform-theme--framework');
885 + inst.dpDiv[0].classList.remove('gform-theme--foundation');
886 + inst.dpDiv[0].classList.remove('gform-theme--orbital');
887 + if (isThemeDatepicker) {
888 + inst.dpDiv[0].classList.add('gform-theme-datepicker');
889 + $(inst.dpDiv[0]).attr('data-parent-form', formId + '_' + formPageInstance);
549 890 }
550 - if ( formTheme === undefined || formTheme === 'gravity-theme' ) {
551 - $( inst.dpDiv[0] ).addClass( 'gravity-theme' );
552 - } else if ( formTheme === 'legacy' ) {
553 - $( inst.dpDiv[0] ).addClass( 'gform-legacy-datepicker' );
891 + if (formTheme === undefined || formTheme === 'gravity-theme') {
892 + $(inst.dpDiv[0]).addClass('gravity-theme');
893 + } else if (formTheme === 'legacy') {
894 + $(inst.dpDiv[0]).addClass('gform-legacy-datepicker');
554 895 }
555 896 else {
556 - $( inst.dpDiv[0] ).addClass( 'gform-theme--' + formTheme );
557 - if ( formTheme === 'orbital' ) {
558 - $( inst.dpDiv[0] ).addClass( 'gform-theme--framework' );
559 - $( inst.dpDiv[0] ).addClass( 'gform-theme--foundation' );
897 + $(inst.dpDiv[0]).addClass('gform-theme--' + formTheme);
898 + if (formTheme === 'orbital') {
899 + $(inst.dpDiv[0]).addClass('gform-theme--framework');
900 + $(inst.dpDiv[0]).addClass('gform-theme--foundation');
560 901 }
561 902 }
562 - if ( isRTL && isPreview ) {
563 - var $inputContainer = $( input ).closest( '.gfield' );
564 - var rightOffset = $( document ).outerWidth() - ( $inputContainer.offset().left + $inputContainer.outerWidth() );
565 - inst.dpDiv[ 0 ].style.right = rightOffset + 'px';
903 + if (isRTL && isPreview) {
904 + var $inputContainer = $(input).closest('.gfield');
905 + var rightOffset = $(document).outerWidth() - ($inputContainer.offset().left + $inputContainer.outerWidth());
906 + inst.dpDiv[0].style.right = rightOffset + 'px';
566 907 }
567 - return ! this.suppressDatePicker;
908 + return !this.suppressDatePicker;
568 909 },
569 910 };
570 911 }
571 912 /**
@@ -573,63 +914,70 @@
573 914 * @description Initialize a datepicker assigning various additional options based on the trigger element.
574 915 * @param $element The datepicker trigger.
575 916 * @since 2.4
576 917 */
577 - function initSingleDatepicker( $element ) {
918 + function initSingleDatepicker($element) {
578 919 var i18n = getDatepickerI18n();
579 - var inputId = $element.attr( 'id' ) ? $element.attr( 'id' ) : '';
580 - var optionsObj = getDatepickerBaseOptions( $element );
581 - if ( $element.hasClass( 'dmy' ) ) {
920 + var inputId = $element.attr('id') ? $element.attr('id') : '';
921 + var optionsObj = getDatepickerBaseOptions($element);
922 + if ($element.hasClass('dmy')) {
582 923 optionsObj.dateFormat = 'dd/mm/yy';
583 - } else if ( $element.hasClass( 'dmy_dash' ) ) {
924 + } else if ($element.hasClass('dmy_dash')) {
584 925 optionsObj.dateFormat = 'dd-mm-yy';
585 - } else if ( $element.hasClass( 'dmy_dot' ) ) {
926 + } else if ($element.hasClass('dmy_dot')) {
586 927 optionsObj.dateFormat = 'dd.mm.yy';
587 - } else if ( $element.hasClass( 'ymd_slash' ) ) {
928 + } else if ($element.hasClass('ymd_slash')) {
588 929 optionsObj.dateFormat = 'yy/mm/dd';
589 - } else if ( $element.hasClass( 'ymd_dash' ) ) {
930 + } else if ($element.hasClass('ymd_dash')) {
590 931 optionsObj.dateFormat = 'yy-mm-dd';
591 - } else if ( $element.hasClass( 'ymd_dot' ) ) {
932 + } else if ($element.hasClass('ymd_dot')) {
592 933 optionsObj.dateFormat = 'yy.mm.dd';
593 934 }
594 - if ( $element.hasClass( 'gdatepicker_with_icon' ) ) {
935 + if ($element.hasClass('gdatepicker_with_icon')) {
595 936 optionsObj.showOn = 'both';
596 - optionsObj.buttonImage = $element.parent().siblings( "[id^='gforms_calendar_icon_input']" ).val();
937 + optionsObj.buttonImage = $element.parent().siblings("[id^='gforms_calendar_icon_input']").val();
597 938 optionsObj.buttonImageOnly = true;
598 939 optionsObj.buttonText = i18n.iconText;
599 940 } else {
600 941 optionsObj.showOn = 'focus';
601 942 }
602 - inputId = inputId.split( '_' );
943 + inputId = inputId.split('_');
603 944 // allow the user to override the datepicker options object
604 - optionsObj = gform.applyFilters( 'gform_datepicker_options_pre_init', optionsObj, inputId[ 1 ], inputId[ 2 ], $element );
605 - $element.datepicker( optionsObj );
606 - // We give the input focus after selecting a date which differs from default Datepicker behavior; this prevents
607 - // users from clicking on the input again to open the datepicker. Let's add a manual click event to handle this.
608 - if ( $element.is( ':input' ) ) {
609 - $element.click( function() {
610 - $element.datepicker( 'show' );
611 - } );
945 + optionsObj = gform.applyFilters('gform_datepicker_options_pre_init', optionsObj, inputId[1], inputId[2], $element);
946 + if (typeof $element.datepicker === 'function') {
947 + $element.datepicker(optionsObj);
948 + // We give the input focus after selecting a date which differs from default Datepicker behavior; this prevents
949 + // users from clicking on the input again to open the datepicker. Let's add a manual click event to handle this.
950 + if ($element.is(':input')) {
951 + $element.click(function () {
952 + $element.datepicker('show');
953 + });
954 + }
612 955 }
613 956 }
614 957 })
615 - $(document).on("change",".gfield--type-repeater_end input,.gfield--type-repeater_end textarea,.gfield--type-repeater_end select",function(event) {
616 - var id = $(this).attr("id");
617 - if (typeof(Storage) !== "undefined") {
618 - if ($(this).attr("name") != "" && typeof $(this).attr("name") != 'undefined') {
619 - var type = $(this).attr("type");
620 - var name = $(this).attr("id");
621 - if( type == "checkbox" ) {
622 - if( $("#"+name+":checked").length > 0 ) {
623 - var value = $("#"+name+":checked").val();
624 - localStorage.setItem(id, value);
625 - }else{
626 - localStorage.removeItem(id);
627 - }
628 - }else{
629 - var value = $(this).val();
630 - localStorage.setItem(id, value);
631 - }
632 - }
633 - }
634 - });
958 + $(document).on("change", ".gfield--type-repeater_end input,.gfield--type-repeater_end textarea,.gfield--type-repeater_end select", function (event) {
959 + var id = $(this).attr("id");
960 + if (typeof (Storage) !== "undefined") {
961 + if ($(this).attr("name") != "" && typeof $(this).attr("name") != 'undefined') {
962 + var type = $(this).attr("type");
963 + var name = $(this).attr("id");
964 + if (type == "checkbox") {
965 + if ($("#" + name + ":checked").length > 0) {
966 + var value = $("#" + name + ":checked").val();
967 + localStorage.setItem(id, value);
968 + } else {
969 + localStorage.removeItem(id);
970 + }
971 + } else if (type == "radio") {
972 + var id = $(this).attr("name");
973 + var value = $(this).val();
974 + localStorage.setItem(id, value);
975 + }
976 + else {
977 + var value = $(this).val();
978 + localStorage.setItem(id, value);
979 + }
980 + }
981 + }
982 + });
635 983 })(jQuery);