Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
31f3ab6
feat(fields): add hooks for dropdown option groups
Crabcyborg Oct 29, 2026
e1a5e90
feat(fields): add dropdown option groups
Crabcyborg Nov 4, 2026
b831269
Merge branch 'master' into feature/option-group-hooks
Crabcyborg Nov 4, 2026
9a8a831
Redesign option groups in the dropdown field settings
Nov 9, 2026
980cbb7
Merge pull request #3677 from Strategy11/option-groups-ui
Crabcyborg Nov 10, 2026
39715af
fix(builder): keep a blank first option out of the first group
Crabcyborg Nov 11, 2026
5c07434
Merge master into feature/option-group-hooks
Crabcyborg Nov 11, 2026
4c1d4f8
Drop formidable-settings-components.js build noise from the PR
Crabcyborg Nov 12, 2026
9e1421b
chore: merge master and rebuild admin assets
Crabcyborg Nov 16, 2026
f8f34d6
Merge remote-tracking branch 'origin/master' into HEAD
Crabcyborg Nov 16, 2026
4ecc211
Merge master into feature/option-group-hooks
Crabcyborg Nov 16, 2026
a0aa4ad
Merge master into feature/option-group-hooks
Crabcyborg Nov 16, 2026
2761b89
Merge master, rebuild formidable_admin.js from source
Crabcyborg Nov 17, 2026
c4a665a
Merge master again, rebuild formidable_admin.js from source
Crabcyborg Nov 17, 2026
ac553c9
Merge remote-tracking branch 'origin/master' into claude/lite-3640
Crabcyborg Nov 17, 2026
f83c52c
Merge remote-tracking branch 'origin/master' into feature/option-grou…
Crabcyborg Nov 18, 2026
fe6375a
Merge remote-tracking branch 'origin/master' into HEAD
Crabcyborg Nov 18, 2026
2c1add6
Keep option group headings out of option values
Crabcyborg Nov 19, 2026
e7a9a4c
Merge master into feature/option-group-hooks
Crabcyborg Nov 19, 2026
8f34034
test(options): cover group names in the builder
Crabcyborg Nov 23, 2026
367197a
Merge branch 'master' into feature/option-group-hooks
Crabcyborg Nov 23, 2026
f5bab88
fix(builder): use admin tokens and patterns for option groups
Crabcyborg Nov 23, 2026
d2f5b03
fix(builder): align option groups tooltip icon
Crabcyborg Nov 25, 2026
768379e
Merge origin/master into feature/option-group-hooks
Crabcyborg Nov 25, 2026
4db2a69
Merge branch 'master' into feature/option-group-hooks
Crabcyborg Nov 25, 2026
3abdd03
perf(builder): avoid scanning option groups on hover
Crabcyborg Nov 26, 2026
dbb7178
Preserve literal dropdown labels in Bulk Edit
Crabcyborg Nov 27, 2026
93a5f8c
Merge remote-tracking branch 'origin/master' into HEAD
Crabcyborg Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion classes/controllers/FrmFieldsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ public static function import_options() {

if ( $field['separate_value'] ) {
foreach ( $opts as $opt_key => $opt ) {
if ( str_contains( $opt, '|' ) ) {
if ( str_contains( $opt, '|' ) && ! FrmOptionGroupsController::is_bulk_edit_group_line( $opt, $field ) ) {
$vals = explode( '|', $opt );
$opts[ $opt_key ] = array(
'label' => trim( $vals[0] ),
Expand All @@ -570,6 +570,8 @@ public static function import_options() {
}
}

$opts = FrmOptionGroupsController::bulk_edit_options( $opts, $field );

// Keep other options after bulk update.
if ( ! empty( $field['field_options']['other'] ) ) {
$other_array = array();
Expand Down
218 changes: 218 additions & 0 deletions classes/controllers/FrmOptionGroupsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
<?php

if ( ! defined( 'ABSPATH' ) ) {
die( 'You are not allowed to call this page directly.' );
}

/**
* Option groups let dropdown options be organized under labeled headings.
*
* The group name is stored on each option as a 'group' key next to 'label' and 'value',
* so anything that reads options without knowing about groups keeps working unchanged.
*
* @since x.x
*/
class FrmOptionGroupsController {

/**
* A line in the Bulk Edit Options text that starts with this marker begins a new group.
* The marker on its own ends the current group.
*
* @var string
*/
const BULK_EDIT_MARKER = '##';

/**
* The label of the optgroup that is currently open while a dropdown is printed.
*
* @var string
*/
private static $open_group = '';

/**
* @since x.x
*
* @param array|object $field The field settings.
*
* @return bool
*/
public static function field_supports_groups( $field ) {
$type = is_array( $field ) ? ( $field['type'] ?? '' ) : $field->type;

if ( 'select' !== $type ) {
return false;
}

$post_field = is_array( $field ) ? ( $field['post_field'] ?? '' ) : FrmField::get_option( $field, 'post_field' );
return 'post_category' !== $post_field;
}

/**
* @since x.x
*
* @param array $field The field settings.
* @param int|string $opt_key The option key.
*
* @return string
*/
public static function get_option_group( $field, $opt_key ) {
$option = $field['options'][ $opt_key ] ?? '';

if ( ! is_array( $option ) || ! isset( $option['group'] ) || ! is_string( $option['group'] ) ) {
return '';
}

return trim( $option['group'] );
}

/**
* Opens or closes an optgroup when the group changes between two options.
*
* @since x.x
*
* @param array $field The field settings.
* @param int|string $opt_key The option key.
*
* @return void
*/
public static function before_dropdown_option( $field, $opt_key ) {
if ( ! self::field_supports_groups( $field ) ) {
return;
}

$group = self::get_option_group( $field, $opt_key );

if ( $group === self::$open_group ) {
return;
}

self::close_open_group();

if ( '' === $group ) {
return;
}

echo '<optgroup label="' . esc_attr( $group ) . '">';
self::$open_group = $group;
}

/**
* @since x.x
*
* @return void
*/
public static function after_dropdown_options() {
self::close_open_group();
}

/**
* @since x.x
*
* @return void
*/
private static function close_open_group() {
if ( '' === self::$open_group ) {
return;
}

echo '</optgroup>';
self::$open_group = '';
}

/**
* Adds the hidden group input to each option row in the builder.
*
* @since x.x
*
* @param array $args Includes the field array and the option key.
*
* @return void
*/
public static function admin_single_opt( $args ) {
$field = $args['field'];

if ( ! self::field_supports_groups( $field ) || FrmFieldsHelper::is_other_opt( $args['opt_key'] ) ) {
return;
}

$input_atts = array(
'type' => 'hidden',
'name' => 'field_options[options_' . $field['id'] . '][' . $args['opt_key'] . '][group]',
'value' => self::get_option_group( $field, $args['opt_key'] ),
'class' => 'frm-option-group-input',
);
?>
<input <?php FrmAppHelper::array_to_html_params( $input_atts, true ); ?> />
<?php
}

/**
* A group line holds a group name, so it is never split into a label and a saved value.
*
* @since x.x
*
* @param string $line One line of the Bulk Edit Options text.
* @param array $field The field the options belong to.
*
* @return bool
*/
public static function is_bulk_edit_group_line( $line, $field ) {
return is_string( $line ) && preg_match( '/^##(?:[ \t]|$)/D', $line ) && self::field_supports_groups( $field );
}

/**
* Turns "## Group name" lines from the Bulk Edit Options text into groups
* for the options that follow them.
*
* @since x.x
*
* @param array $opts One item per line, either a string or an array with 'label' and 'value'.
* @param array $field The field the options belong to.
*
* @return array
*/
public static function bulk_edit_options( $opts, $field ) {
if ( ! is_array( $opts ) || ! self::field_supports_groups( $field ) ) {
return $opts;
}

$grouped_opts = array();
$group = '';

foreach ( $opts as $opt ) {
$label = is_array( $opt ) ? (string) ( $opt['label'] ?? '' ) : (string) $opt;

if ( is_string( $opt ) && self::is_bulk_edit_group_line( $opt, $field ) ) {
$group = trim( substr( $label, strlen( self::BULK_EDIT_MARKER ) ) );
continue;
}

if ( str_starts_with( $label, '\\' ) && self::is_bulk_edit_group_line( ltrim( $label, '\\' ), $field ) ) {
$label = substr( $label, 1 );

if ( is_array( $opt ) ) {
$opt['label'] = $label;
} else {
$opt = $label;
}
}

if ( '' === $group ) {
$grouped_opts[] = $opt;
continue;
}

if ( ! is_array( $opt ) ) {
$opt = array(
'label' => $opt,
'value' => $opt,
);
}

$opt['group'] = $group;
$grouped_opts[] = $opt;
}//end foreach

return $grouped_opts;
}
}
4 changes: 4 additions & 0 deletions classes/views/frm-fields/front-end/dropdown-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
$option_params['disabled'] = 'disabled';
}

FrmOptionGroupsController::before_dropdown_option( $field, $opt_key );

echo '<option ';
FrmAppHelper::array_to_html_params( $option_params, true );
selected( (bool) $selected );
Expand All @@ -96,6 +98,8 @@

unset( $option_params );
}//end foreach

FrmOptionGroupsController::after_dropdown_options();
?>
</select>
<?php
Expand Down
5 changes: 4 additions & 1 deletion classes/views/frm-fields/single-option.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,8 @@
?>
</span>

<?php do_action( 'frm_admin_single_opt', compact( 'field', 'opt', 'opt_key' ) ); ?>
<?php
FrmOptionGroupsController::admin_single_opt( compact( 'field', 'opt_key' ) );
do_action( 'frm_admin_single_opt', compact( 'field', 'opt', 'opt_key' ) );
?>
</li>
2 changes: 1 addition & 1 deletion css/frm_admin.css

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion js/formidable_admin.js

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions js/src/admin/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { syncFieldOrder, confirmFieldOrderSaved } = require( './fieldOrder' );
const { allowContainerDrop } = require( './fieldPlacement' );
const { getRangeSettingsDefaults, validateNumberRangeSetting, validateStepSetting, validateRangeSettings } = require( './settings/validateRangeSettings' );
const { initFieldListHoverPill } = require( './fieldListHoverPill' );
const { setupOptionGroups, initOptionGroupLists, refreshOptionGroups, formatBulkOptionLabel } = require( './optionGroups' );
const { initShowBoxIconSwap } = require( './showBoxIconSwap' );
const { initFieldSizePreview } = require( './fieldSizePreview' );
const { hydrateBuilderSelect, hydrateBuilderSelectsIn } = require( './sharedSelectOptions' );
Expand Down Expand Up @@ -4875,6 +4876,7 @@ window.frmAdminBuildJS = function() {
return;
}
let content = '';
const groupState = { previous: '' };
const fieldId = jQuery( this ).closest( '[data-fid]' ).data( 'fid' );
const separate = usingSeparateValues( fieldId );
const product = isProductField( fieldId );
Expand All @@ -4893,7 +4895,7 @@ window.frmAdminBuildJS = function() {
if ( key !== '000' ) {
const label = document.getElementsByName( `field_options[options_${ fieldId }][${ key }][label]` )[ 0 ];
if ( label !== undefined ) {
content += label.value;
content += formatBulkOptionLabel( opts[ i ], label.value, groupState );
if ( separate ) {
content += `|${ document.getElementsByName( `field_options[options_${ fieldId }][${ key }][value]` )[ 0 ].value }`;
}
Expand All @@ -4903,12 +4905,10 @@ window.frmAdminBuildJS = function() {
content += '\r\n';
}
}

if ( i >= opts.length - 1 ) {
document.getElementById( 'frm_bulk_options' ).value = content;
}
}

document.getElementById( 'frm_bulk_options' ).value = content;

$info.dialog( 'open' );

return false;
Expand Down Expand Up @@ -8254,7 +8254,8 @@ window.frmAdminBuildJS = function() {
}

const container = document.getElementById( `frm_field_${ fieldId }_opts` );
const conflicts = Array.from( container.querySelectorAll( 'input[type="text"]' ) ).filter(
// A group heading holds a name, not an option, so an option may share its text.
const conflicts = Array.from( container.querySelectorAll( 'input[type="text"]:not(.frm-option-group-name)' ) ).filter(
input => input.id !== targetInput.id &&
areValuesSeparate === input.name.endsWith( '[value]' ) &&
input.value === targetInput.value
Expand Down Expand Up @@ -9542,6 +9543,7 @@ window.frmAdminBuildJS = function() {
);
}

initOptionGroupLists( singleField );
wp.hooks.doAction( 'frmShowedFieldSettings', obj, singleField );
maybeAddShortcodesModalTriggerIcon( fieldType, fieldId, singleField );

Expand Down Expand Up @@ -12767,6 +12769,7 @@ window.frmAdminBuildJS = function() {

document.querySelectorAll( '.field_type_list > li:not(.frm_show_upgrade):not(.frm_show_update)' ).forEach( makeDraggable );
initFieldListHoverPill();
setupOptionGroups();
initFieldSizePreview();

jQuery( 'ul.field_type_list, .field_type_list li, ul.frm_code_list, .frm_code_list li, .frm_code_list li a, #frm_adv_info #category-tabs li, #frm_adv_info #category-tabs li a' ).disableSelection();
Expand Down Expand Up @@ -13491,6 +13494,7 @@ window.frmAdminBuildJS = function() {
},
success( html ) {
document.getElementById( `frm_field_${ fieldId }_opts` ).innerHTML = html;
refreshOptionGroups( fieldId );
wp.hooks.doAction( 'frm_after_bulk_edit_opts', fieldId );
resetDisplayedOpts( fieldId );

Expand Down
Loading