: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
/* global wpforms_builder, wpf, jconfirm, wpforms_panel_switch, Choices, WPForms, WPFormsFormEmbedWizard, wpCookies, tinyMCE, WPFormsUtils, List, wpforms_preset_choices */
/* noinspection JSUnusedLocalSymbols */
/* eslint-disable no-unused-expressions, no-shadow */
// noinspection ES6ConvertVarToLetConst
var WPFormsBuilder = window.WPFormsBuilder || ( function( document, window, $ ) { // eslint-disable-line no-var
* Whether to show the close confirmation dialog or not.
let closeConfirmation = true;
// noinspection JSUnusedGlobalSymbols
/* eslint-disable camelcase */
spinner: '<i class="wpforms-loading-spinner"></i>',
spinnerInline: '<i class="wpforms-loading-spinner wpforms-loading-inline"></i>',
tinymce: { toolbar1: 'bold,italic,underline,blockquote,strikethrough,bullist,numlist,alignleft,aligncenter,alignright,undo,redo,link' },
choicesLimit: 20, // Choices limit for fields different from Dropdown.
choicesLimitLong: 250, // Choices limit for Dropdown field.
wpforms_panel_switch = true;
$( window ).on( 'load', function() {
// In the case of jQuery 3.+, we need to wait for a ready event first.
if ( typeof $.ready.then === 'function' ) {
$.ready.then( app.load );
$( window ).on( 'beforeunload', function() {
if ( ! that.formIsSaved() && closeConfirmation ) {
return wpforms_builder.are_you_sure_to_close;
* @since 1.7.9 Added `wpformsBuilderReady` hook.
* @return {false|void} False if default event is prevented.
// Trigger initial save for new forms.
if ( wpf.getQueryString( 'newform' ) ) {
const panel = $( '#wpforms-panels-toggle .active' ).data( 'panel' );
// Render form preview on the Revisions panel if the panel is active.
if ( panel === 'revisions' ) {
app.updateRevisionPreview();
// Allow callbacks to prevent making Form Builder ready...
const event = WPFormsUtils.triggerEvent( $builder, 'wpformsBuilderReady' );
// ...by triggering `event.preventDefault()`.
if ( event.isDefaultPrevented() ) {
// Hide loading overlay and make the Form Builder ready to use.
app.hideLoadingOverlay();
// Maybe display informational modal.
// noinspection JSUnresolvedReference, EqualityComparisonWithCoercionJS
if ( wpforms_builder.template_modal_display == '1' && 'fields' === wpf.getQueryString( 'view' ) ) { // eslint-disable-line
title: wpforms_builder.template_modal_title,
content: wpforms_builder.template_modal_msg,
icon: 'fa fa-info-circle',
text: wpforms_builder.close,
ready() { // eslint-disable-line max-lines-per-function
if ( app.isVisitedViaBackButton() ) {
// Cache builder element.
$builder = $( '#wpforms-builder' );
elements.$helpButton = $( '#wpforms-help' );
elements.$previewButton = $( '#wpforms-preview-btn' );
elements.$embedButton = $( '#wpforms-embed' );
elements.$saveButton = $( '#wpforms-save' );
elements.$exitButton = $( '#wpforms-exit' );
elements.$noFieldsOptions = $( '#wpforms-panel-fields .wpforms-no-fields-holder .no-fields' );
elements.$noFieldsPreview = $( '#wpforms-panel-fields .wpforms-no-fields-holder .no-fields-preview' );
elements.$formPreview = $( '#wpforms-panel-fields .wpforms-preview-wrap' );
elements.$revisionPreview = $( '#wpforms-panel-revisions .wpforms-panel-content' );
elements.defaultEmailSelector = '.wpforms-field-option-email .wpforms-field-option-row-default_value input';
elements.$defaultEmail = $( elements.defaultEmailSelector );
elements.$focusOutTarget = null;
elements.$nextFieldId = $( '#wpforms-field-id' );
elements.$fieldOptions = $( '#wpforms-field-options' );
elements.$fieldsPreviewWrap = $( '#wpforms-panel-fields .wpforms-panel-content-wrap' );
elements.$sortableFieldsWrap = $( '#wpforms-panel-fields .wpforms-field-wrap' );
elements.$addFieldsButtons = $( '.wpforms-add-fields-button' ).not( '.not-draggable' ).not( '.warning-modal' ).not( '.education-modal' );
elements.$fieldsSidebar = $( '#wpforms-panel-fields .wpforms-add-fields' );
elements.$searchInput = $( '#wpforms-search-fields-input' );
elements.$sidebarToggle = $( '.wpforms-panels .wpforms-panel-sidebar-content .wpforms-panel-sidebar-toggle' );
// Add `_wp_http_referer` to the data of every AJAX request.
// eslint-disable-next-line camelcase
_wp_http_referer: wpf.updateQueryString( '_wp_http_referer', null ),
// Remove Embed button if builder opened in the popup.
if ( app.isBuilderInPopup() ) {
elements.$embedButton.remove();
elements.$previewButton.addClass( 'wpforms-alone' );
// Setup/cache some vars not available before
s.formID = $( '#wpforms-builder-form' ).data( 'id' );
s.pagebreakTop = $( '.wpforms-pagebreak-top' ).length;
s.pagebreakBottom = $( '.wpforms-pagebreak-bottom' ).length;
// Disable implicit submission for every form inside the builder.
// All form values are managed by JS and should not be submitted by pressing Enter.
$builder.on( 'keypress', '#wpforms-builder-form :input:not(textarea)', function( e ) {
if ( e.keyCode === 13 ) {
// If there is a section configured, display it.
// Otherwise, we show the first panel by default.
$( '.wpforms-panel' ).each( function( index, el ) { // eslint-disable-line no-unused-vars
$configured = $this.find( '.wpforms-panel-sidebar-section.configured' ).first();
if ( $configured.length ) {
const section = $configured.data( 'section' );
$configured.addClass( 'active' );
$this.find( '.wpforms-panel-content-section-' + section ).show().addClass( 'active' );
$this.find( '.wpforms-panel-content-section-default' ).hide();
$this.find( '.wpforms-panel-content-section:first-of-type' ).show().addClass( 'active' );
$this.find( '.wpforms-panel-sidebar-section:first-of-type' ).addClass( 'active' );
app.loadEntryPreviewFields();
// Drag and drop sortable elements.
app.fieldChoiceSortable( 'select' );
app.fieldChoiceSortable( 'radio' );
app.fieldChoiceSortable( 'checkbox' );
app.fieldChoiceSortable( 'payment-multiple' );
app.fieldChoiceSortable( 'payment-checkbox' );
app.fieldChoiceSortable( 'payment-select' );
// Set field group visibility.
$( '.wpforms-add-fields-group' ).each( function( index, el ) { // eslint-disable-line no-unused-vars
app.fieldGroupToggle( $( this ), 'load' );
// Trim long form titles.
// Hide/Show CAPTCHA in form.
// Confirmations' initial setup.
app.confirmationsSetup();
// Notification settings.
app.notificationToggle();
app.notificationsByStatusAlerts();
// Secret builder hotkeys.
// jquery-confirm defaults.
backgroundDismiss: false,
animateFromElement: false,
content: wpforms_builder.something_went_wrong,
app.dropdownField.init();
app.checkEmptyDynamicChoices();
app.initSomeFieldOptions();
checkEmptyDynamicChoices() {
const choices = wpf.orders.choices || {};
if ( ! Object.keys( choices ).length ) {
wpf.orders.fields.forEach( function( fieldId ) { // eslint-disable-line complexity
const isDynamic = app.dropdownField.helpers.isDynamicChoices( fieldId );
const $fieldPreview = $( '#wpforms-field-' + fieldId );
const type = app.dropdownField.helpers.getDynamicChoicesOptionType( fieldId );
const source = app.dropdownField.helpers.getDynamicChoicesOptionSource( fieldId );
const isModern = app.dropdownField.helpers.isDynamicChoicesOptionModern( fieldId );
? $fieldPreview.find( '.has-no-choices' ).length
: $fieldPreview.find( '.primary-input option:not(.placeholder), .primary-input li' ).length === 0;
if ( isModern && ! isEmpty ) {
const placeholder = $( '#wpforms-field-option-' + fieldId + '-placeholder' ).val();
const choices = app.dropdownField.helpers.getInitialChoices( fieldId );
isEmpty = choices.length === 1 && choices[ 0 ].label === placeholder && choices[ 0 ].placeholder === true;
app.emptyChoicesNotice( fieldId, source, type );
* Load Microsoft Windows specific stylesheet.
const ua = navigator.userAgent;
if ( ua.indexOf( 'Macintosh' ) !== -1 ) {
href: wpforms_builder.scrollbars_css_url,
* Builder was visited via back button in the browser.
* @return {boolean} True if the builder was visited via back button in browser.
isVisitedViaBackButton() {
let isVisitedViaBackButton = false;
performance.getEntriesByType( 'navigation' ).forEach( function( nav ) {
if ( nav.type === 'back_forward' ) {
isVisitedViaBackButton = true;
return isVisitedViaBackButton;
* Remove loading overlay.
const $overlay = $( '#wpforms-builder-overlay' );
$overlay.addClass( 'fade-out' );
const $overlay = $( '#wpforms-builder-overlay' );
$overlay.removeClass( 'fade-out' );
* Initialize some fields options controls.
// Show a toggled options groups.
app.toggleAllOptionGroups( $builder );
// Date/Time field Date type option.
$builder.find( '.wpforms-field-option-row-date .type select' ).trigger( 'change' );
* Dropdown field component.
modernClass: 'choicesjs-select',
const $element = $( this.containerOuter.element ),
$previewSelect = $element.closest( '.wpforms-field' ).find( 'select' );
// Turn off disabled styles.
if ( $element.hasClass( 'is-disabled' ) ) {
$element.removeClass( 'is-disabled' );
// Disable instances on the preview panel.
if ( $previewSelect.is( '[readonly]' ) ) {
$previewSelect.prop( 'disabled', false );
if ( this.passedElement.element.multiple ) {
// Hide a placeholder if field has selected choices.
if ( this.getValue( true ).length ) {
$( this.input.element ).addClass( 'choices__input--hidden' );
* Initialization for field component.
$builder.find( '.' + app.dropdownField.config.modernClass ).each( function() {
app.dropdownField.events.choicesInit( $( this ) );
'.wpforms-field-option-select .wpforms-field-option-row-multiple input',
app.dropdownField.events.multiple
'.wpforms-field-option-select .wpforms-field-option-row-style select, .wpforms-field-option-payment-select .wpforms-field-option-row-style select',
app.dropdownField.events.applyStyle
// Add the ability to close the drop-down menu.
$builder.on( 'click', '.choices', function( e ) {
const $choices = $( this ),
choicesObj = $choices.find( 'select' ).data( 'choicesjs' );
$choices.hasClass( 'is-open' ) &&
e.target.classList.contains( 'choices__inner' )
choicesObj.hideDropdown();
* Load Choices.js library.
* @param {Object} $element jQuery element selector.
choicesInit( $element ) {