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

Refactor: update Honorific block to only accept labels and add field validation #7564

Merged
merged 7 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"@fortawesome/free-solid-svg-icons": "^5.15.1",
"@fortawesome/react-fontawesome": "^0.1.12",
"@givewp/design-system-foundation": "^1.1.0",
"@givewp/form-builder-library": "^1.6.0",
"@givewp/form-builder-library": "^1.7.0",
"@hookform/error-message": "^2.0.1",
"@hookform/resolvers": "^2.9.10",
"@paypal/paypal-js": "^5.1.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ protected function createNodeFromBlockWithUniqueAttributes(BlockModel $block, in
}

/**
* @unreleased updated honorific field with validation
*
* @since 3.0.0
*/
protected function createNodeFromDonorNameBlock(BlockModel $block): Node
Expand Down Expand Up @@ -293,9 +295,13 @@ protected function createNodeFromDonorNameBlock(BlockModel $block): Node


if ($block->hasAttribute('showHonorific') && $block->getAttribute('showHonorific') === true) {
$group->getNodeByName('honorific')
->label('Title')
->options(...array_values($block->getAttribute('honorifics')));
$options = array_values((array)$block->getAttribute('honorifics'));
Copy link
Contributor

@JoshuaHungDinh JoshuaHungDinh Oct 4, 2024

Choose a reason for hiding this comment

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

Should we check for empty strings when passing the options? I found you can add an empty option and it will display. Not a big deal i'm not sure why someone would add a label and not fill it out but it's just something I noticed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice catch! resolved f3eed61

if (!empty($options)){
$group->getNodeByName('honorific')
->label(__('Title', 'give'))
->options(...$options)
->rules('max:255', 'in:' . implode(',', $options));
}
} else {
$group->remove('honorific');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export default function Edit({
selectable={false}
options={honorificOptions}
setOptions={setOptions}
toggleEnabled={false}
defaultControlsTooltip={__('Title Prefixes', 'give')}
/>
</div>
Expand Down
Loading