Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contact Form: add extra field settings to base field #34704

Merged
merged 2 commits into from
Dec 19, 2023
Merged
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

Contact Form: add extra field settings to base field
2 changes: 1 addition & 1 deletion projects/packages/forms/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"link-template": "https://github.com/automattic/jetpack-forms/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "0.27.x-dev"
"dev-trunk": "0.28.x-dev"
},
"textdomain": "jetpack-forms",
"version-constants": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/forms/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-forms",
"version": "0.27.0",
"version": "0.28.0-alpha",
"description": "Jetpack Forms",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/forms/#readme",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ToggleControl,
RangeControl,
} from '@wordpress/components';
import { isValidElement } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { useFormStyle, FORM_STYLE, getBlockStyle } from '../util/form';
import ToolbarRequiredGroup from './block-controls/toolbar-required-group';
Expand All @@ -31,6 +32,7 @@ const JetpackFieldControls = ( {
setAttributes,
type,
width,
extraFieldSettings = [],
} ) => {
const formStyle = useFormStyle( clientId );
const blockStyle = getBlockStyle( blockClassNames );
Expand Down Expand Up @@ -103,6 +105,50 @@ const JetpackFieldControls = ( {
setAttributes( { id: newValue } );
};

let fieldSettings = [
<ToggleControl
label={ __( 'Field is required', 'jetpack-forms' ) }
className="jetpack-field-label__required"
checked={ required }
onChange={ value => setAttributes( { required: value } ) }
help={ __( 'You can edit the "required" label in the editor', 'jetpack-forms' ) }
/>,
! hidePlaceholder && (
<TextControl
label={ __( 'Placeholder text', 'jetpack-forms' ) }
value={ placeholder || '' }
onChange={ value => setAttributes( { [ placeholderField ]: value } ) }
help={ __(
'Show visitors an example of the type of content expected. Otherwise, leave blank.',
'jetpack-forms'
) }
/>
),
<JetpackFieldWidth setAttributes={ setAttributes } width={ width } />,
<ToggleControl
label={ __( 'Sync fields style', 'jetpack-forms' ) }
checked={ attributes.shareFieldAttributes }
onChange={ value => setAttributes( { shareFieldAttributes: value } ) }
help={ __( 'Deactivate for individual styling of this block', 'jetpack-forms' ) }
/>,
];

extraFieldSettings.forEach( ( { element, index } ) => {
if ( ! isValidElement( element ) ) {
return;
}

if ( index >= 0 && index < fieldSettings.length ) {
fieldSettings = [
...fieldSettings.slice( 0, index ),
element,
...fieldSettings.slice( index ),
];
} else {
fieldSettings.push( element );
}
} );

return (
<>
<BlockControls>
Expand All @@ -117,31 +163,9 @@ const JetpackFieldControls = ( {
<JetpackManageResponsesSettings isChildBlock />
</PanelBody>
<PanelBody title={ __( 'Field Settings', 'jetpack-forms' ) }>
<ToggleControl
label={ __( 'Field is required', 'jetpack-forms' ) }
className="jetpack-field-label__required"
checked={ required }
onChange={ value => setAttributes( { required: value } ) }
help={ __( 'You can edit the "required" label in the editor', 'jetpack-forms' ) }
/>
{ ! hidePlaceholder && (
<TextControl
label={ __( 'Placeholder text', 'jetpack-forms' ) }
value={ placeholder || '' }
onChange={ value => setAttributes( { [ placeholderField ]: value } ) }
help={ __(
'Show visitors an example of the type of content expected. Otherwise, leave blank.',
'jetpack-forms'
) }
/>
) }
<JetpackFieldWidth setAttributes={ setAttributes } width={ width } />
<ToggleControl
label={ __( 'Sync fields style', 'jetpack-forms' ) }
checked={ attributes.shareFieldAttributes }
onChange={ value => setAttributes( { shareFieldAttributes: value } ) }
help={ __( 'Deactivate for individual styling of this block', 'jetpack-forms' ) }
/>
{ fieldSettings.filter( Boolean ).map( ( elt, index ) => (
<div key={ index }>{ elt }</div>
) ) }
</PanelBody>
<PanelColorSettings
title={ __( 'Color', 'jetpack-forms' ) }
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/forms/src/class-jetpack-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
class Jetpack_Forms {

const PACKAGE_VERSION = '0.27.0';
const PACKAGE_VERSION = '0.28.0-alpha';

/**
* Load the contact form module.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: other
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/jetpack/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading