Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Add support for setting custom ID on hidden field blocks from block settings
63 changes: 36 additions & 27 deletions projects/packages/forms/src/blocks/field-hidden/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useBlockProps } from '@wordpress/block-editor';
import { Placeholder, TextControl, __experimentalHStack as HStack } from '@wordpress/components'; // eslint-disable-line @wordpress/no-unsafe-wp-apis
import { __ } from '@wordpress/i18n';
import { unseen } from '@wordpress/icons';
import JetpackFieldControls from '../shared/components/jetpack-field-controls.js';
import useFormWrapper from '../shared/hooks/use-form-wrapper.js';
import useInsertAfterOnEnterKeyDown from '../shared/hooks/use-insert-after-on-enter-key-down.js';
import './editor.scss';
Expand All @@ -22,32 +23,40 @@ export default function HiddenFieldEdit( props ) {
const onKeyDown = useInsertAfterOnEnterKeyDown( clientId, true );

return (
<div { ...blockProps }>
<Placeholder icon={ unseen } label={ __( 'Hidden field', 'jetpack-forms' ) }>
<HStack alignment="top" className="jetpack-form-hidden-field-inputs">
<TextControl
__next40pxDefaultSize
__nextHasNoMarginBottom
onChange={ handleLabelChange }
label={ __( 'Name', 'jetpack-forms' ) }
value={ attributes.label }
help={ __(
'Internal name used to identify this field in form responses.',
'jetpack-forms'
) }
onKeyDown={ onKeyDown }
/>
<TextControl
__next40pxDefaultSize
__nextHasNoMarginBottom
onChange={ handleValueChange }
label={ __( 'Value', 'jetpack-forms' ) }
value={ attributes.default }
help={ __( 'The value that will be submitted with the form.', 'jetpack-forms' ) }
onKeyDown={ onKeyDown }
/>
</HStack>
</Placeholder>
</div>
<>
<div { ...blockProps }>
<Placeholder icon={ unseen } label={ __( 'Hidden field', 'jetpack-forms' ) }>
<HStack alignment="top" className="jetpack-form-hidden-field-inputs">
<TextControl
__next40pxDefaultSize
__nextHasNoMarginBottom
onChange={ handleLabelChange }
label={ __( 'Name', 'jetpack-forms' ) }
value={ attributes.label }
help={ __(
'Internal name used to identify this field in form responses.',
'jetpack-forms'
) }
onKeyDown={ onKeyDown }
/>
<TextControl
__next40pxDefaultSize
__nextHasNoMarginBottom
onChange={ handleValueChange }
label={ __( 'Value', 'jetpack-forms' ) }
value={ attributes.default }
help={ __( 'The value that will be submitted with the form.', 'jetpack-forms' ) }
onKeyDown={ onKeyDown }
/>
</HStack>
</Placeholder>
</div>
<JetpackFieldControls
id={ attributes.id }
setAttributes={ setAttributes }
attributes={ attributes }
extraFieldSettings={ [] }
/>
</>
);
}
1 change: 1 addition & 0 deletions projects/packages/forms/src/blocks/field-hidden/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const settings = {
edit,
save,
attributes: {
id: { type: 'string' },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
id: { type: 'string' },
id: { type: 'string', default: '' },

It's important to add default here so that when users enter ID but then remove it, we don't serialize empty ID as <!-- wp:jetpack/field-hidden {"id":""} /--> in block markup.

label: { type: 'string', default: '' },
default: { type: 'string', default: '' },
},
Expand Down
Loading