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