From 8ad1b791b6f9c90ca828d0704ed67a184dcd880e Mon Sep 17 00:00:00 2001 From: Matthias Kittsteiner Date: Wed, 13 Sep 2023 17:13:23 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20radio=20buttons=20with=20i?= =?UTF-8?q?dentical=20name=20Closes=20#29?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/form-data/class-data.php | 7 ++++++- src/input/controls.js | 7 ++++++- src/input/edit.js | 10 +++++++++- src/input/html-data.js | 2 ++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/inc/form-data/class-data.php b/inc/form-data/class-data.php index 2b897be..868c38e 100644 --- a/inc/form-data/class-data.php +++ b/inc/form-data/class-data.php @@ -523,7 +523,12 @@ public function set_static_value_output( string $output, string $name, $value, a return sprintf( __( 'Checked: %s', 'form-block' ), $label ); } else if ( $field_data['type'] === 'radio' ) { - /* translators: form field title */ + if ( $value !== 'on' ) { + /* translators: form field title or value */ + return sprintf( __( 'Selected: %s', 'form-block' ), $value ); + } + + /* translators: form field title or value */ return sprintf( __( 'Selected: %s', 'form-block' ), $label ); } diff --git a/src/input/controls.js b/src/input/controls.js index 2648c62..2cfa3cd 100644 --- a/src/input/controls.js +++ b/src/input/controls.js @@ -57,7 +57,12 @@ export default function Controls( props ) { }, ]; - if ( type === 'reset' || type === 'submit' ) { + if ( + type === 'checkbox' + || type === 'radio' + || type === 'reset' + || type === 'submit' + ) { defaultControlTypes.push( { attributeName: 'value', attributes: {}, diff --git a/src/input/edit.js b/src/input/edit.js index 7676d1a..6e49eff 100644 --- a/src/input/edit.js +++ b/src/input/edit.js @@ -99,7 +99,15 @@ export default function InputEdit( props ) { ? setAttributes( { label } ) } + onChange={ ( newLabel ) => { + const oldLabel = label; + + setAttributes( { label: newLabel } ); + + if ( ! value || value === oldLabel ) { + setAttributes( { value: newLabel } ); + } + } } placeholder={ __( 'Label', 'form-block' ) } tagName="label" value={ label || '' } diff --git a/src/input/html-data.js b/src/input/html-data.js index dc039f5..4d86d05 100644 --- a/src/input/html-data.js +++ b/src/input/html-data.js @@ -23,6 +23,7 @@ const types = applyFilters( 'disabled', 'label', 'required', + 'value', ], }, email: { @@ -72,6 +73,7 @@ const types = applyFilters( 'disabled', 'label', 'required', + 'value', ], }, reset: {