: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
/* global wpforms_builder_settings, Choices, wpf */
* Form Builder Settings Panel module.
var WPForms = window.WPForms || {};
WPForms.Admin = WPForms.Admin || {};
WPForms.Admin.Builder = WPForms.Admin.Builder || {};
WPForms.Admin.Builder.Settings = WPForms.Admin.Builder.Settings || ( function( document, window, $ ) {
* Public functions and properties.
* Setup. Prepare some variables.
$builder: $( '#wpforms-builder' ),
$panel: $( '#wpforms-panel-settings' ),
$selectTags: $( '#wpforms-panel-field-settings-form_tags' ),
.on( 'keydown', '#wpforms-panel-field-settings-form_tags-wrap input', app.addCustomTagInput )
.on( 'removeItem', '#wpforms-panel-field-settings-form_tags-wrap select', app.editTagsRemoveItem );
.on( 'change', app.changeTags );
* Init Choices.js on the Tags select input element.
// Skip in certain cases.
! el.$selectTags.length ||
typeof window.Choices !== 'function'
// Init Choices.js object instance.
vars.tagsChoicesObj = new Choices( el.$selectTags[0], wpforms_builder_settings.choicesjs_config );
var currentValue = vars.tagsChoicesObj.getValue( true );
// Update all tags choices.
wpforms_builder_settings.all_tags_choices,
.setChoiceByValue( currentValue );
el.$selectTags.data( 'choicesjs', vars.tagsChoicesObj );
app.initTagsHiddenInput();
* Init Tags hidden input element.
initTagsHiddenInput: function() {
// Create additional hidden input.
el.$selectTagsHiddenInput = $( '<input type="hidden" name="settings[form_tags_json]">' );
.closest( '.wpforms-panel-field' )
.append( el.$selectTagsHiddenInput );
// Update hidden input value.
// Update form state when hidden input initialized.
// This will prevent a please-save-prompt to appear, when switching from revisions without doing any changes anywhere.
if ( wpf.initialSave === true ) {
wpf.savedState = wpf.getFormState( '#wpforms-builder-form' );
* Add custom item to Tags dropdown on input.
* @param {object} event Event object.
addCustomTagInput: function( event ) {
if ( [ 'Enter', ',' ].indexOf( event.key ) < 0 ) {
if ( ! vars.tagsChoicesObj || event.target.value.length === 0 ) {
var tagLabel = _.escape( event.target.value ).trim(),
labels = _.map( vars.tagsChoicesObj.getValue(), 'label' ).map( function( label ) {
return label.toLowerCase().trim();
if ( tagLabel === '' || labels.indexOf( tagLabel.toLowerCase() ) >= 0 ) {
vars.tagsChoicesObj.clearInput();
app.addCustomTagInputCreate( tagLabel );
* Remove tag from Tags field event handler.
* @param {object} event Event object.
editTagsRemoveItem: function( event ) {
var allValues = _.map( wpforms_builder_settings.all_tags_choices, 'value' );
if ( allValues.indexOf( event.detail.value ) >= 0 ) {
// We should remove new tag from the list of choices.
var choicesObj = $( event.target ).data( 'choicesjs' ),
currentValue = choicesObj.getValue( true ),
choices = _.filter( choicesObj._currentState.choices, function( item ) {
return item.value !== event.detail.value;
.setChoices( choices, 'value', 'label', true )
.setChoiceByValue( currentValue );
* Add custom item to Tags dropdown on input (second part).
* @param {object} tagLabel Event object.
addCustomTagInputCreate: function( tagLabel ) {
var tag = _.find( wpforms_builder_settings.all_tags_choices, { label: tagLabel } );
if ( tag && tag.value ) {
vars.tagsChoicesObj.setChoiceByValue( tag.value );
vars.tagsChoicesObj.setChoices(
vars.tagsChoicesObj.clearInput();
* Change Tags field event handler.
* @param {object} event Event object.
changeTags: function( event ) {
var tagsValue = vars.tagsChoicesObj.getValue(),
for ( var i = 0; i < tagsValue.length; i++ ) {
value: tagsValue[ i ].value,
label: tagsValue[ i ].label,
// Update Tags field hidden input value.
el.$selectTagsHiddenInput.val(
// Provide access to public functions/properties.
}( document, window, jQuery ) );
WPForms.Admin.Builder.Settings.init();