";
jQuery("#bulk_items").prepend(str);
}
}
function SelectCustomChoice( name ){
jQuery("#gfield_bulk_add_input").val(gform_custom_choices[name].join("\n"));
gform_selected_custom_choice = name;
InitBulkCustomPanel();
}
function SelectPredefinedChoice(name){
jQuery('#gfield_bulk_add_input').val(gform_predefined_choices[name].join('\n'));
gform_selected_custom_choice = "";
InitBulkCustomPanel();
}
function InsertBulkChoices(choices){
field = GetSelectedField();
field.choices = new Array();
var enableValue = false;
for(var i=0; i 1){
var currency = GetCurrentCurrency();
price = currency.toMoney(text_price[1]);
}
text_value = text_value.split("|");
if(text_value.length > 1)
enableValue = true;
choice = new Choice(jQuery.trim(text_value[0]), jQuery.trim(text_value[text_value.length -1]), jQuery.trim(price));
/**
* Filter each individual Choice object as it is inserted into the UI.
*
* This filter is generally used in combination with gform_load_bulk_choices_choice, and is useful
* for parsing a unique text pattern (e.g., Label|Value|Other) and adding the additional data to
* the resulting Choice object.
*
* @since 2.5
*
* @param {Choice} choice The Choice object representing this particular Choice data.
* @param {string} choice_string The string representing the current choice as a text pattern.
* @param {object} field The current field being evaluated.
*
* @return {Choice} The updated Choice object containing any additional data needed.
*/
choice = gform.applyFilters( 'gform_insert_bulk_choices_choice', choice, choices[i], field );
field.choices.push( choice );
}
/**
* Fires after bulk choices have been added to the field object and before the UI has been re-rendered.
*
* This action is useful if you need to alter other field settings based on the choices.
*
* @since 2.3
*
* @param array field The currently selected field object.
*/
gform.doAction( 'gform_bulk_insert_choices', field );
if(enableValue){
field["enableChoiceValue"] = true;
jQuery('#field_choice_values_enabled').prop("checked", true);
ToggleChoiceValue();
}
LoadFieldChoices(field);
UpdateFieldChoices( GetInputType( field ) );
}
function InitBulkCustomPanel(){
if(gform_selected_custom_choice.length == 0){
CloseCustomChoicesPanel();
}
else{
LoadCustomChoicesPanel();
}
}
function LoadCustomChoicesPanel(isNew, speed){
if(isNew){
jQuery("#custom_choice_name").val("");
jQuery("#bulk_save_button").html(gf_vars.save);
jQuery("#bulk_cancel_link").show();
jQuery("#bulk_delete_link").hide();
}
else{
jQuery("#custom_choice_name").val(gform_selected_custom_choice);
jQuery("#bulk_save_button").html(gf_vars.update);
jQuery("#bulk_cancel_link").hide();
jQuery("#bulk_delete_link").show();
}
jQuery("#bulk_save_as").hide();
jQuery("#bulk_custom_edit").show();
}
function CloseCustomChoicesPanel(){
jQuery("#bulk_save_as").show();
jQuery("#bulk_custom_edit").hide();
}
function IsEmpty(array){
var key;
for (key in array) {
if (array.hasOwnProperty(key))
return false;
}
return true;
}
function SetFieldChoice(inputType, index){
var text = jQuery("#" + inputType + "_choice_text_" + index).val();
var value = jQuery("#" + inputType + "_choice_value_" + index).val();
var price = jQuery("#" + inputType + "_choice_price_" + index).val();
field = GetSelectedField();
field.choices[index].text = text;
field.choices[index].value = field.enableChoiceValue ? value : text;
if(field.enablePrice){
var currency = GetCurrentCurrency();
var price = currency.toMoney(price);
if(!price)
price = "";
field.choices[index]["price"] = price;
}
//set field selections
jQuery("#field_choices :radio, #field_choices :checkbox").each(function(index){
field.choices[index].isSelected = this.checked;
});
LoadBulkChoices(field);
UpdateFieldChoices(GetInputType(field));
}
function SetInputChoice(inputId, index, value, text){
var field = GetSelectedField();
var input = GetInput(field, inputId);
inputId = inputId.toString().replace('.', '_');
input.choices[index].text = text;
input.choices[index].value = input.enableChoiceValue ? value : text;
//set field selections
jQuery(".field-input-choice-" + inputId + ":radio, .field-input-choice-" + inputId + ":checkbox").each(function(index){
input.choices[index].isSelected = this.checked;
});
UpdateInputChoices(input);
}
function UpdateFieldChoices(fieldType){
var choices = '';
var selector = '';
var inputContainer = ( "1" === gf_legacy.is_legacy ) ? 'li' : 'div';
var inputContainerClass;
if(fieldType == "checkbox")
field.inputs = new Array();
var skip = 0;
// Multiselect is functionally just a select input with a different attribute; adjust the type here.
if ( fieldType === 'multiselect' ) {
fieldType = 'select';
}
switch( fieldType ){
case "select" :
for(var i=0; i" + field.choices[i].text + "";
}
break;
case "checkbox" :
for(var i=0; i" + inputContainer + ">";
}
if(field.choices.length > 5)
choices += "<" + inputContainer + " class='gchoice_total'>" + gf_vars["editToViewAll"].replace("%d", field.choices.length) + "" + inputContainer + ">";
if ( field.enableSelectAll ) {
choices += '';
}
break;
case "radio" :
for(var i=0; i" + inputContainer + ">";
}
choices += field.enableOtherChoice ? "<" + inputContainer + ">" + inputContainer + ">" : "";
if(field.choices.length > 5)
choices += "<" + inputContainer + " class='gchoice_total'>" + gf_vars["editToViewAll"].replace("%d", field.choices.length) + "" + inputContainer + ">";
break;
case "list" :
RefreshSelectedFieldPreview();
break;
}
selector = '.gfield_' + fieldType;
jQuery(".field_selected " + selector).html(choices);
}
function UpdateInputChoices(input){
var choices = '';
for(var i=0; i" + input.choices[i].text + "";
}
var inputId = input.id.toString().replace('.', '_');
jQuery(".field_selected #input_" + inputId).html(choices);
}
function InsertFieldChoice( index ) {
field = GetSelectedField();
var inputType = GetInputType( field );
var text = "";
var value = "";
var price = field[ "enablePrice" ] ? "0.00" : "";
if ( inputType === 'list' ) {
text = window.gf_vars.column + " " + (index + 1);
value = window.gf_vars.column + " " + (index + 1);
}
var newChoice = new Choice( text, value, price );
if ( window[ "gform_new_choice_" + field.type ] ) {
newChoice = window[ "gform_new_choice_" + field.type ]( field, newChoice );
}
if ( typeof field.choices !== 'object' ) {
field.choices = [];
}
field.choices.splice( index, 0, newChoice );
LoadFieldChoices( field );
UpdateFieldChoices( inputType );
}
function InsertInputChoice($ul, inputId, index){
var field = GetSelectedField();
var input = GetInput(field, inputId);
var new_choice = new Choice("", "");
input.choices.splice(index, 0, new_choice);
LoadInputChoices($ul, input);
UpdateInputChoices(input);
}
function DeleteFieldChoice(index){
field = GetSelectedField();
var value = jQuery('#' + GetInputType(field) + '_choice_value_' + index).val();
if( HasConditionalLogicDependency(field.id, value) ) {
if(!confirm(gf_vars.conditionalLogicDependencyChoice))
return;
}
field.choices.splice(index, 1);
LoadFieldChoices(field);
UpdateFieldChoices(GetInputType(field));
}
function DeleteInputChoice($ul, inputId, index){
var field = GetSelectedField();
var input = GetInput(field, inputId);
input.choices.splice(index, 1);
LoadInputChoices($ul, input);
UpdateInputChoices(input);
}
function MoveFieldChoice(fromIndex, toIndex){
field = GetSelectedField();
var choice = field.choices[fromIndex];
//deleting from old position
field.choices.splice(fromIndex, 1);
//inserting into new position
field.choices.splice(toIndex, 0, choice);
LoadFieldChoices(field);
UpdateFieldChoices(GetInputType(field));
}
function MoveInputChoice($ul, inputId, fromIndex, toIndex){
var field = GetSelectedField();
var input = GetInput(field, inputId);
var choice = input.choices[fromIndex];
//deleting from old position
input.choices.splice(fromIndex, 1);
//inserting into new position
input.choices.splice(toIndex, 0, choice);
LoadInputChoices($ul, input);
UpdateInputChoices(input);
}
function GetFieldType(fieldId){
return fieldId.substr(0, fieldId.lastIndexOf("_"));
}
function GetSelectedField() {
var $field = jQuery( '.field_selected' );
if( $field.length <= 0 ) {
return false;
}
var id = $field[0].id.substr( 6 );
return GetFieldById( id );
}
function SetPasswordProperty(isChecked){
SetFieldProperty("enablePasswordInput", isChecked);
}
function ToggleDateCalendar( isInit ){
var dateType = jQuery("#field_date_input_type").val();
if(dateType == "datefield" || dateType == "datedropdown"){
jQuery("#date_picker_container").hide();
SetCalendarIconType("none");
}
else{
jQuery("#date_picker_container").show();
}
}
function ToggleCalendarIconUrl( isInit ){
if(jQuery("#gsetting_icon_custom").is(":checked")){
jQuery("#gfield_icon_url_container").show();
}
else{
jQuery("#gfield_icon_url_container").hide();
jQuery("#gfield_calendar_icon_url").val("");
SetFieldProperty('calendarIconUrl', '');
}
}
function SetTimeFormat(format){
SetFieldProperty('timeFormat', format);
LoadTimeInputs();
}
function LoadTimeInputs(){
var field = GetSelectedField();
if(field.type != 'time' && field.inputType != 'time'){
return;
}
var format = jQuery("#field_time_format").val();
if(format == "24"){
jQuery('#input_default_value_row_input_' + field.id +'_3').hide();
jQuery(".field_selected .gfield_time_ampm").hide();
} else {
jQuery('#input_default_value_row_input_' + field.id +'_3').show();
jQuery(".field_selected .gfield_time_ampm").show();
}
jQuery('#input_placeholder_row_input_' + field.id +'_3').hide(); // No support for placeholder.
// AM/PM Sub label is hidden in the time field class after `gform_post_load_field_settings` is fired.
}
/**
* Set date format for a date field.
*
* @since unknown
* @since 2.5 Updated for the layout editor.
*
* @param format
* @constructor
*/
function SetDateFormat( format ) {
SetFieldProperty( 'dateFormat', format );
var field = GetSelectedField();
if ( field.dateType === 'datepicker' ) {
var formatLabel = jQuery( '#field_date_format option:selected' ).text();
if ( field.placeholder === '' ) {
jQuery( '.field_selected input[name="ginput_datepicker"]' )
.attr( 'placeholder', formatLabel );
}
}
LoadDateInputs();
}
function LoadDateInputs(){
var type = jQuery("#field_date_input_type").val();
var format = jQuery("#field_date_format").val();
//setting up field positions
var position = format ? format.substr(0,3) : "mdy";
if(type == "datefield"){
switch(position){
case "ymd" :
jQuery(".field_selected #gfield_input_date_month").remove().insertBefore(".field_selected #gfield_input_date_day");
jQuery(".field_selected #gfield_input_date_year").remove().insertBefore(".field_selected #gfield_input_date_month");
break;
case "mdy" :
jQuery(".field_selected #gfield_input_date_day").remove().insertBefore(".field_selected #gfield_input_date_year");
jQuery(".field_selected #gfield_input_date_month").remove().insertBefore(".field_selected #gfield_input_date_day");
break;
case "dmy" :
jQuery(".field_selected #gfield_input_date_month").remove().insertBefore(".field_selected #gfield_input_date_year");
jQuery(".field_selected #gfield_input_date_day").remove().insertBefore(".field_selected #gfield_input_date_month");
break;
}
jQuery(".field_selected [id^='gfield_input_date']").show();
jQuery(".field_selected [id^='gfield_dropdown_date']").hide();
jQuery(".field_selected #gfield_input_datepicker").hide();
jQuery(".field_selected #gfield_input_datepicker_icon").hide();
}
else if(type == "datedropdown"){
switch(position){
case "ymd" :
jQuery(".field_selected #gfield_dropdown_date_month").remove().insertBefore(".field_selected #gfield_dropdown_date_day");
jQuery(".field_selected #gfield_dropdown_date_year").remove().insertBefore(".field_selected #gfield_dropdown_date_month");
break;
case "mdy" :
jQuery(".field_selected #gfield_dropdown_date_day").remove().insertBefore(".field_selected #gfield_dropdown_date_year");
jQuery(".field_selected #gfield_dropdown_date_month").remove().insertBefore(".field_selected #gfield_dropdown_date_day");
break;
case "dmy" :
jQuery(".field_selected #gfield_dropdown_date_month").remove().insertBefore(".field_selected #gfield_dropdown_date_year");
jQuery(".field_selected #gfield_dropdown_date_day").remove().insertBefore(".field_selected #gfield_dropdown_date_month");
break;
}
jQuery(".field_selected [id^='gfield_dropdown_date']").css("display", "inline");
jQuery(".field_selected [id^='gfield_input_date']").hide();
jQuery(".field_selected #gfield_input_datepicker").hide();
jQuery(".field_selected #gfield_input_datepicker_icon").hide();
}
else{
jQuery(".field_selected [id^='gfield_input_date']").hide();
jQuery(".field_selected [id^='gfield_dropdown_date']").hide();
jQuery(".field_selected #gfield_input_datepicker").show();
//Displaying or hiding the calendar icon
if(jQuery("#gsetting_icon_calendar").is(":checked"))
jQuery(".field_selected #gfield_input_datepicker_icon").show();
else
jQuery(".field_selected #gfield_input_datepicker_icon").hide();
}
}
function SetCalendarIconType(iconType, isInit){
field = GetSelectedField();
if(GetInputType(field) != "date")
return;
if(iconType == undefined)
iconType = "none";
if(iconType == "none")
jQuery("#gsetting_icon_none").prop("checked", true);
else if(iconType == "calendar")
jQuery("#gsetting_icon_calendar").prop("checked", true);
else if(iconType == "custom")
jQuery("#gsetting_icon_custom").prop("checked", true);
SetFieldProperty('calendarIconType', iconType);
ToggleCalendarIconUrl( isInit );
LoadDateInputs();
}
function SetDateInputType(type){
field = GetSelectedField();
if(GetInputType(field) != "date")
return;
if ( type === 'datepicker' ) {
SetFieldAccessibilityWarning( 'date_input_type_setting', 'above' );
} else {
resetAllFieldAccessibilityWarnings();
}
field.dateType = type;
field.inputs = GetDateFieldInputs(field);
CreateDefaultValuesUI(field);
CreatePlaceholdersUI(field);
CreateInputLabelsUI(field);
ToggleDateSettings(field);
ResetDefaultInputValues(field);
ToggleDateCalendar();
LoadDateInputs();
}
function SetPostImageMeta(){
var displayAlt = jQuery('#gfield_display_alt').is(":checked");
var displayTitle = jQuery('#gfield_display_title').is(":checked");
var displayCaption = jQuery('#gfield_display_caption').is(":checked");
var displayDescription = jQuery('#gfield_display_description').is(":checked");
var displayLabel = (displayAlt || displayTitle || displayCaption || displayDescription);
//setting property
SetFieldProperty('displayAlt', displayAlt);
SetFieldProperty('displayTitle', displayTitle);
SetFieldProperty('displayCaption', displayCaption);
SetFieldProperty('displayDescription', displayDescription);
//updating UI
jQuery('.field_selected .ginput_post_image_alt').css("display", displayAlt ? "block" : "none");
jQuery('.field_selected .ginput_post_image_title').css("display", displayTitle ? "block" : "none");
jQuery('.field_selected .ginput_post_image_caption').css("display", displayCaption ? "block" : "none");
jQuery('.field_selected .ginput_post_image_description').css("display", displayDescription ? "block" : "none");
jQuery('.field_selected .ginput_post_image_file').css("display", displayLabel ? "block" : "none");
}
function SetFeaturedImage() {
var isChecked = jQuery('#gfield_featured_image').is(':checked');
if(isChecked) {
for(i in form.fields) {
if(!form.fields.hasOwnProperty(i))
continue;
form.fields[i].postFeaturedImage = false;
}
SetFieldProperty('postFeaturedImage', true);
}
else{
SetFieldProperty('postFeaturedImage', false);
}
}
function SetFieldProperty(name, value){
if (value == undefined)
value = "";
var field = GetSelectedField();
var previousValue = rgar( field, name );
field[name] = value;
/**
* Enables custom actions to be performed when a field property is set.
*
* @since 2.7.16
*
* @param {string} name The name of the property that was set.
* @param {object} field The field object that was updated.
* @param {(string|number|boolean|array)} value The current value of the specified property.
* @param {(string|number|boolean|array)} previousValue The previous value of the specified property.
*/
window.gform.doAction( 'gform_post_set_field_property', name, field, value, previousValue );
}
function SetInputName(value, inputId){
var field = GetSelectedField();
if(value)
value = value.trim();
if(!inputId){
field["inputName"] = value;
}
else{
for(var i=0; i b["text"].toLowerCase() );});
}
function SetFieldLabel(label){
var requiredElement = jQuery(".field_selected .gfield_required")[0];
jQuery(".field_selected label.gfield_label, .field_selected .gsection_title, .field_selected legend.gfield_label > span").text(label).append(requiredElement);
SetFieldProperty("label", label);
var nativeEvent = new Event('gform/form_editor/set_field_label');
document.dispatchEvent(nativeEvent);
}
/**
* Set the Aria Label for a field in the editor.
*
* @since 2.5.
*
* @param {string} label The field label
*/
function SetAriaLabel(label){
var fieldId = jQuery( ".field_selected" )[0].id.split( '_' )[1];
var field = GetFieldById( fieldId );
var ariaLabel = window.gf_vars.fieldLabelAriaLabel.replace('{field_label}', label).replace('{field_type}', field.type);
jQuery( ".field_selected .gfield-edit" ).attr( 'aria-label', ariaLabel );
}
function SetCaptchaTheme(theme, thumbnailUrl){
jQuery(".field_selected .gfield_captcha").attr("src", thumbnailUrl);
SetFieldProperty("captchaTheme", theme);
}
function SetCaptchaSize(size){
var type = jQuery("#field_captcha_type").val();
SetFieldProperty("simpleCaptchaSize", size);
RedrawCaptcha();
jQuery(".field_selected .gfield_captcha_input_container").removeClass(type + "_small").removeClass(type + "_medium").removeClass(type + "_large").addClass(type + "_" + size);
}
function SetCaptchaFontColor(color){
SetFieldProperty("simpleCaptchaFontColor", color);
RedrawCaptcha();
}
function SetCaptchaBackgroundColor(color){
SetFieldProperty("simpleCaptchaBackgroundColor", color);
RedrawCaptcha();
}
function RedrawCaptcha(){
var captchaType = jQuery("#field_captcha_type").val();
if(captchaType == "math"){
url_1 = GetCaptchaUrl(1);
url_2 = GetCaptchaUrl(2);
url_3 = GetCaptchaUrl(3);
jQuery(".field_selected .gfield_captcha:eq(0)").attr("src", url_1);
jQuery(".field_selected .gfield_captcha:eq(1)").attr("src", url_2);
jQuery(".field_selected .gfield_captcha:eq(2)").attr("src", url_3);
}
else{
url = GetCaptchaUrl();
jQuery(".field_selected .gfield_captcha").attr("src", url);
}
}
function SetFieldEnhancedUI( checked ) {
SetFieldProperty( 'enableEnhancedUI', checked ? 1 : 0 );
if ( checked ) {
SetFieldAccessibilityWarning( 'enable_enhanced_ui_setting', 'below' );
} else {
resetAllFieldAccessibilityWarnings();
}
}
function SetFieldSize(size){
jQuery(".field_selected .small, .field_selected .medium, .field_selected .large").removeClass("small").removeClass("medium").removeClass("large").addClass(size);
SetFieldProperty("size", size);
}
function SetFieldLabelPlacement(labelPlacement){
var labelPlacementClass = labelPlacement ? labelPlacement : form.labelPlacement;
SetFieldProperty("labelPlacement", labelPlacement);
jQuery(".field_selected").removeClass("top_label").removeClass("right_label").removeClass("left_label").removeClass("hidden_label").addClass(labelPlacementClass);
if((field.labelPlacement == 'left_label' || field.labelPlacement == 'right_label' || (field.labelPlacement == '' && form.labelPlacement != 'top_label'))){
jQuery('#field_description_placement').val('');
SetFieldProperty("descriptionPlacement", '');
jQuery('#field_description_placement_container').hide('slow');
} else {
jQuery('#field_description_placement_container').show('slow');
}
if ( field.labelPlacement == 'hidden_label' ) {
SetFieldAccessibilityWarning( 'label_placement_setting', 'above' );
} else {
resetAllFieldAccessibilityWarnings();
}
SetFieldProperty("labelPlacement", labelPlacement);
SetFieldRequired(field.isRequired);
RefreshSelectedFieldPreview();
}
function SetFieldDescriptionPlacement(descriptionPlacement){
var isDescriptionAbove = descriptionPlacement == 'above' || (descriptionPlacement == '' && form.descriptionPlacement == 'above)');
SetFieldProperty("descriptionPlacement", descriptionPlacement);
RefreshSelectedFieldPreview(function(){
if(isDescriptionAbove){
jQuery(".field_selected").addClass("description_above");
} else {
jQuery(".field_selected").removeClass("description_above");
}
});
}
function SetFieldSubLabelPlacement( subLabelPlacement ) {
SetFieldProperty( "subLabelPlacement", subLabelPlacement );
RefreshSelectedFieldPreview( function() {
if ( "above" === subLabelPlacement ) {
jQuery( ".field_selected" ).addClass( "field_sublabel_above" ).removeClass( "field_sublabel_below" );
} else {
jQuery( ".field_selected" ).addClass( "field_sublabel_below" ).removeClass( "field_sublabel_above" );
}
} );
}
function SetFieldVisibility( visibility, handleInputs, isInit ) {
if (!isInit && visibility == 'administrative' && HasConditionalLogicDependency(field.id)) {
if( ! confirm( gf_vars.conditionalLogicDependencyAdminOnly ) ) {
return false;
}
}
var isWhitelisted = false;
for( var i = 0; i < gf_vars.visibilityOptions.length; i++ ) {
if( gf_vars.visibilityOptions[i].value == visibility ) {
isWhitelisted = true;
break;
}
}
if( ! isWhitelisted ) {
visibility = 'visible';
}
SetFieldProperty( 'visibility', visibility );
if( handleInputs ) {
var $inputs = jQuery( 'input[name="field_visibility"]' );
$inputs.prop( 'checked', false );
$inputs.filter( '[value="' + visibility + '"]' ).prop( 'checked', true );
}
}
function SetFieldDefaultValue(defaultValue){
jQuery(".field_selected > div > input:visible, .field_selected > div > textarea:visible, .field_selected > div > select:visible").val(defaultValue);
SetFieldProperty('defaultValue', defaultValue);
}
function SetFieldPlaceholder(placeholder){
jQuery(".field_selected > div > input:visible, .field_selected > div > textarea:visible, .field_selected > div > select:visible").each(function(){
var type = this.nodeName;
var $this = jQuery(this);
if(type == 'INPUT' || type == 'TEXTAREA'){
jQuery(this).prop("placeholder", placeholder);
} else if (type == 'SELECT'){
var $option = $this.find('option[value=""]');
if($option.length>0){
if(placeholder.length > 0){
$option.text(placeholder);
} else {
$option.remove();
}
} else {
$this.prepend('');
$this.val('');
}
}
});
SetFieldProperty('placeholder', placeholder);
}
function SetFieldDescription(description){
if(description == undefined)
description = "";
SetFieldProperty('description', description);
}
function SetFieldCheckboxLabel(text){
if(text == undefined)
text = "";
SetFieldProperty('checkboxLabel', text);
}
function SetPasswordStrength(isEnabled){
if(isEnabled){
jQuery(".field_selected .gfield_password_strength").show();
}
else{
jQuery(".field_selected .gfield_password_strength").hide();
//resetting min strength
jQuery("#gfield_min_strength").val("");
SetFieldProperty('minPasswordStrength', "");
}
SetFieldProperty('passwordStrengthEnabled', isEnabled);
}
function ToggleEmailSettings(field){
var isConfirmEnabled = typeof field.emailConfirmEnabled != 'undefined' && field.emailConfirmEnabled == true;
jQuery('.placeholder_setting').toggle(!isConfirmEnabled);
jQuery('.default_value_setting').toggle(!isConfirmEnabled);
jQuery('.sub_label_placement_setting').toggle(isConfirmEnabled);
jQuery('.sub_labels_setting').toggle(isConfirmEnabled);
jQuery('.default_input_values_setting').toggle(isConfirmEnabled);
jQuery('.input_placeholders_setting').toggle(isConfirmEnabled);
}
function SetEmailConfirmation(isEnabled){
var field = GetSelectedField();
if(isEnabled){
jQuery(".field_selected .ginput_single_email").hide();
jQuery(".field_selected .ginput_confirm_email").show();
}
else{
jQuery(".field_selected .ginput_confirm_email").hide();
jQuery(".field_selected .ginput_single_email").show();
}
field['emailConfirmEnabled'] = isEnabled;
field.inputs = GetEmailFieldInputs(field);
CreateDefaultValuesUI(field);
CreatePlaceholdersUI(field);
CreateAutocompleteUI(field);
CreateCustomizeInputsUI(field);
CreateInputLabelsUI(field);
ToggleEmailSettings(field);
}
function SetCardType(elem, value) {
var cards = GetSelectedField()['creditCards'] ? GetSelectedField()['creditCards'] : new Array();
if(jQuery(elem).is(':checked')) {
if(jQuery.inArray(value, cards) == -1) {
jQuery('.gform_card_icon_' + value).fadeIn();
cards[cards.length] = value;
}
} else {
var index = jQuery.inArray(value, cards);
if(index != -1) {
jQuery('.gform_card_icon_' + value).fadeOut();
cards.splice(index, 1);
}
}
SetFieldProperty('creditCards', cards);
}
function SetFieldRequired( isRequired ) {
var required = gform_form_strings.requiredIndicator;
var requiredSelector = '.field_selected .gfield_required';
var appendRequired = false;
if ( field.type === 'consent' ) {
jQuery( requiredSelector ).remove();
if ( isRequired ) {
appendRequired = true;
}
} else if ( jQuery( requiredSelector ).length > 0 ) {
if ( isRequired ) {
jQuery( requiredSelector ).html( required );
} else {
jQuery( requiredSelector ).remove();
}
} else if ( isRequired ) {
appendRequired = true;
}
if ( appendRequired ) {
var labelSelector = field.type === 'consent' && field.labelPlacement === 'hidden_label' ? '.field_selected .gfield_consent_label' : '.field_selected legend.gfield_label span, .field_selected label.gfield_label';
jQuery( labelSelector ).append( '' + required + '' );
}
SetFieldProperty( 'isRequired', isRequired );
}
function SetMaxLength(input) {
var patt = GetMaxLengthPattern();
var cleanValue = '';
var characters = input.value.split('');
for(i in characters) {
if(!characters.hasOwnProperty(i))
continue;
if( !patt.test(characters[i]) )
cleanValue += characters[i];
}
input.value = cleanValue;
SetFieldProperty('maxLength', cleanValue);
}
function GetMaxLengthPattern() {
return /[a-zA-Z\-!@#$%^&*();'":_+=<,>.~`?\/|\[\]\{\}\\]/;
}
/**
* Validate any keypress events based on a provided RegExp.
*
* Function retrieves the character code from the keypress event and tests it against provided pattern.
* Optionally specify 'matchPositive' argument to false in order to return true if the character is NOT
* in the provided pattern.
*
* @param event The JS keypress event.
* @param patt RegExp to test keypress character against.
* @param matchPositive Defaults to true. Whether to return true if the character is found or NOT found in the pattern.
*/
function ValidateKeyPress(event, patt, matchPositive) {
var matchPositive = typeof matchPositive == 'undefined' ? true : matchPositive;
var char = event['which'] ? event.which : event.keyCode;
var isMatch = patt.test(String.fromCharCode(char));
if(event.ctrlKey)
return true;
return matchPositive ? isMatch : !isMatch;
}
function IndexOf(ary, item){
for(var i=0; i
').appendTo("body");jQuery(document.createElement("div")).attr("id","iColorPickerBg").click(function(){jQuery("#iColorPickerBg").hide();jQuery("#iColorPicker").fadeOut()}).appendTo("body");jQuery('table.pickerTable td').css({'width':'12px','height':'14px','border':'1px solid #000','cursor':'pointer'});jQuery('#iColorPicker table.pickerTable').css({'border-collapse':'collapse'});jQuery('#iColorPicker').css({'border':'1px solid #ccc','background':'#333','padding':'5px','color':'#fff','z-index':9999})}
jQuery('#colorPreview').css({'height':'50px'});
})
};
jQuery(function(){iColorPicker()});
function SetColorPickerColor(field_name, color, callback){
var chip = jQuery('#chip_' + field_name);
chip.css("background-color", color);
if(callback)
window[callback](color);
}
jQuery( document ).mouseup( function( e ) {
var container = jQuery( "#iColorPicker" );
if ( ! container.is( e.target ) && container.has( e.target ).length === 0 ) {
jQuery( "#iColorPickerBg" ).hide();
jQuery( "#iColorPicker" ).fadeOut();
}
} );
function SetFieldChoices(){
var field = GetSelectedField();
for(var i=0; i {
$container = jQuery( '.field_selected .field-' + type + '-message-content' );
messageMarkup = $container && $container.length ? gform_strip_scripts( $container.html() ) : '';
if ( messageMarkup ) {
jQuery( '#sidebar_field_message_container .gform-alert__message' ).html( messageMarkup );
jQuery( '#sidebar_field_message_container .gform-alert' ).addClass( 'gform-alert--' + ( type === 'warning' ? 'error' : type ) );
iconClasses.forEach(
( className ) => {
jQuery( '#sidebar_field_message_container .gform-icon' ).addClass( className );
}
);
// Add class to force this notice visible, as all field notices are reset when a field is selected.
if ( type === 'notice' ) {
jQuery( '#sidebar_field_message_container .gform-alert' ).addClass( 'gform-visible-notice' );
}
showSidebarMessage = true;
wp.a11y.speak( messageMarkup );
} else {
jQuery( '#sidebar_field_message_container' ).hide();
}
}
);
if ( showSidebarMessage ) {
jQuery( '#sidebar_field_message_container' ).show();
jQuery( '#sidebar_field_message_container .gform-alert' ).show();
}
}
/**
* Set the field error for a field settings.
*
* We add the field setting to the "errors" field property and display the error
* message next to the setting.
*
* @since 2.5
*
* @param {string} fieldSetting The field setting class name.
* @param {string} position The position to put the warning, can be 'above' or 'below'.
* @param {string} [message] The message to be set in the warning.
*/
function setFieldError( fieldSetting, position, message ) {
var field = GetSelectedField();
// Make sure this field can have errors.
if ( field.type == 'page' ||
field.type == 'section' ||
field.type == 'html' ) {
return;
}
var errorProperties = [ fieldSetting ];
// Extra rules for the label setting.
if ( fieldSetting === 'label_setting' ) {
var fieldPlaceholder = field.hasOwnProperty( 'placeholder' ) ? field.placeholder : '';
var fieldDescription = field.hasOwnProperty( 'description' ) ? field.description : '';
if ( fieldPlaceholder !== '' || fieldDescription !== '' ) {
SetFieldAccessibilityWarning( 'label_setting', 'below' );
resetFieldError( 'label_setting' );
return;
} else {
ResetFieldAccessibilityWarning( 'label_setting' );
}
}
// Set up error property list to the "errors" property.
if ( field.hasOwnProperty( 'errors' ) && ! field.errors.includes( fieldSetting ) ) {
errorProperties = errorProperties.concat( field.errors );
}
SetFieldProperty( 'errors', errorProperties );
// Get the error message.
if ( message === undefined ) {
message = getFieldErrorMessage( fieldSetting );
}
var errorDiv = '
';
errorDiv += '';
errorDiv += '
' + message + '
';
errorDiv += '
';
// Display the error message.
var fieldSettingContainer = jQuery( '.' + fieldSetting );
fieldSettingContainer.addClass( 'error' );
jQuery( '.gform-alert--error[data-field-setting="' + fieldSetting + '"]' ).remove();
if ( position === 'above' ) {
fieldSettingContainer.before( errorDiv );
} else {
fieldSettingContainer.after( errorDiv );
}
}
/**
* Reset the field error for a field setting.
*
* @since 2.5
*
* @param {string} [fieldSetting] The field setting class name.
*/
function resetFieldError( fieldSetting ) {
var field = GetSelectedField();
var errorProperties = field.hasOwnProperty( 'errors' ) ? field.errors : [];
if ( typeof fieldSetting !== 'undefined' ) {
jQuery( '.gform-alert--error[data-field-setting="' + fieldSetting + '"]' ).remove()
jQuery( '.' + fieldSetting ).removeClass( 'error' );
var index = errorProperties.indexOf( fieldSetting );
// Delete the field property from the errors.
if ( index > -1 ) {
if ( errorProperties.length > 1 ) {
delete errorProperties[ index ];
} else {
errorProperties = [];
}
}
}
SetFieldProperty( 'errors', errorProperties );
}
/**
* Reset the field errors for all field settings.
*
* @since 2.5.8
*/
function resetAllFieldErrors() {
if ( ! jQuery( '.field_setting' ).hasClass( 'error' ) ) {
return;
}
jQuery('.editor-sidebar .gform-alert--error').remove();
jQuery('.field_setting').filter('.error').removeClass( 'error' );
if ( form.fields.length > 0 ) {
form.fields.forEach( function( field ) {
if( field.hasOwnProperty( 'errors' ) && field.errors.length > 0 ) {
field.errors = [];
}
} );
}
}
/**
* Check if a given field or the selected field has errors.
*
* @since 2.5
*
* @param {object} [field] The field object.
*
* @return {boolean}
*/
function fieldHasError( field ) {
if ( typeof field === 'undefined' ) {
field = GetSelectedField();
}
if ( field.hasOwnProperty( 'errors' ) && field.errors.length > 0 ) {
return true;
}
return false;
}