Skip to content

Commit

Permalink
🐛 Fix radio buttons with identical name
Browse files Browse the repository at this point in the history
Closes #29
  • Loading branch information
MatzeKitt committed Sep 13, 2023
1 parent 305c268 commit 8ad1b79
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
7 changes: 6 additions & 1 deletion inc/form-data/class-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down
7 changes: 6 additions & 1 deletion src/input/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down
10 changes: 9 additions & 1 deletion src/input/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,15 @@ export default function InputEdit( props ) {
? <FlexBlock>
<RichText
className="form-block__label"
onChange={ ( label ) => 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 || '' }
Expand Down
2 changes: 2 additions & 0 deletions src/input/html-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const types = applyFilters(
'disabled',
'label',
'required',
'value',
],
},
email: {
Expand Down Expand Up @@ -72,6 +73,7 @@ const types = applyFilters(
'disabled',
'label',
'required',
'value',
],
},
reset: {
Expand Down

0 comments on commit 8ad1b79

Please sign in to comment.