Skip to content

Commit

Permalink
adding options for date
Browse files Browse the repository at this point in the history
  • Loading branch information
iruzevic committed Aug 8, 2023
1 parent 331f1cc commit 6f13484
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion eightshift-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Description: Eightshift Forms is a complete form builder plugin that utilizes modern Block editor features with multiple third-party integrations, bringing your project to a new level.
* Author: WordPress team @Infinum
* Author URI: https://eightshift.com/
* Version: 4.0.58
* Version: 4.0.59
* Text Domain: eightshift-forms
*
* @package EightshiftForms
Expand Down
23 changes: 16 additions & 7 deletions src/Blocks/components/date/components/date-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const DateOptions = (attributes) => {
const dateValidationPattern = checkAttr('dateValidationPattern', attributes, manifest);
const dateDisabledOptions = checkAttr('dateDisabledOptions', attributes, manifest);
const dateType = checkAttr('dateType', attributes, manifest);
const dateUseLabelAsPlaceholder = checkAttr('dateUseLabelAsPlaceholder', attributes, manifest);

let dateValidationPatternOptions = [];

Expand Down Expand Up @@ -79,13 +80,21 @@ export const DateOptions = (attributes) => {
noSearch
/>

<TextControl
label={<IconLabel icon={icons.fieldPlaceholder} label={__('Placeholder', 'eightshift-forms')} />}
help={__('Shown when the field is empty', 'eightshift-forms')}
value={datePlaceholder}
onChange={(value) => setAttributes({ [getAttrKey('datePlaceholder', attributes, manifest)]: value })}
disabled={isOptionDisabled(getAttrKey('datePlaceholder', attributes, manifest), dateDisabledOptions)}
className='es-no-field-spacing'
{!dateUseLabelAsPlaceholder &&
<TextControl
label={<IconLabel icon={icons.fieldPlaceholder} label={__('Placeholder', 'eightshift-forms')} />}
help={__('Shown when the field is empty', 'eightshift-forms')}
value={datePlaceholder}
onChange={(value) => setAttributes({ [getAttrKey('datePlaceholder', attributes, manifest)]: value })}
disabled={isOptionDisabled(getAttrKey('datePlaceholder', attributes, manifest), dateDisabledOptions)}
className='es-no-field-spacing'
/>
}
<IconToggle
icon={icons.fieldPlaceholder}
label={__('Use label as placeholder', 'eightshift-forms')}
checked={dateUseLabelAsPlaceholder}
onChange={(value) => setAttributes({ [getAttrKey('dateUseLabelAsPlaceholder', attributes, manifest)]: value })}
/>
</Section>

Expand Down
8 changes: 8 additions & 0 deletions src/Blocks/components/date/date.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
$datePreviewFormat = Components::checkAttr('datePreviewFormat', $attributes, $manifest);
$dateOutputFormat = Components::checkAttr('dateOutputFormat', $attributes, $manifest);
$dateFieldAttrs = Components::checkAttr('dateFieldAttrs', $attributes, $manifest);
$dateUseLabelAsPlaceholder = Components::checkAttr('dateUseLabelAsPlaceholder', $attributes, $manifest);

// Fix for getting attribute that is part of the child component.
$dateHideLabel = false;
$dateFieldLabel = $attributes[Components::getAttrKey('dateFieldLabel', $attributes, $manifest)] ?? '';

$dateClass = Components::classnames([
Expand All @@ -57,6 +59,11 @@
$dateAttrs[AbstractBaseRoute::CUSTOM_FORM_DATA_ATTRIBUTES['dateOutputFormat']] = esc_attr($dateOutputFormat);
}

if ($dateUseLabelAsPlaceholder) {
$dateAttrs['placeholder'] = esc_attr($dateFieldLabel);
$dateHideLabel = true;
}

$dateAttrsOutput = '';
if ($dateAttrs) {
foreach ($dateAttrs as $key => $value) {
Expand Down Expand Up @@ -91,6 +98,7 @@ class="' . esc_attr($dateClass) . '"
'fieldDisabled' => !empty($dateIsDisabled),
'fieldTypeCustom' => $dateTypeCustom ?: $dateType, // phpcs:ignore WordPress.PHP.DisallowShortTernary.Found
'fieldTracking' => $dateTracking,
'fieldHideLabel' => $dateHideLabel,
'fieldConditionalTags' => Components::render(
'conditional-tags',
Components::props('conditionalTags', $attributes)
Expand Down
4 changes: 4 additions & 0 deletions src/Blocks/components/date/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
"type": "boolean",
"default": false
},
"dateUseLabelAsPlaceholder": {
"type": "boolean",
"default": false
},
"dateIsReadOnly": {
"type": "boolean",
"default": false
Expand Down

0 comments on commit 6f13484

Please sign in to comment.