Skip to content

Commit 2c802cc

Browse files
committed
MAGE-986 Enhance checkbox UI with help text
1 parent 2b4dbae commit 2c802cc

File tree

2 files changed

+72
-12
lines changed

2 files changed

+72
-12
lines changed

Block/Adminhtml/System/Config/Form/Field/Checkboxes.php

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,77 @@ class Checkboxes extends Field
99
{
1010
protected function _getElementHtml(AbstractElement $element)
1111
{
12-
$html = '';
12+
$elementId = $element->getHtmlId();
13+
$html = <<<CSS
14+
<style>
15+
#$elementId .form-group {
16+
display: grid;
17+
grid-template-columns: 24px 1fr;
18+
align-items: start;
19+
margin-bottom: 20px;
20+
}
21+
22+
#$elementId .form-group input[type="checkbox"] {
23+
margin-top: 2px;
24+
}
25+
#$elementId .form-content {
26+
display: flex;
27+
flex-direction: column;
28+
}
29+
#$elementId .form-content label {
30+
font-weight: bold;
31+
color: #333;
32+
}
33+
#$elementId .form-content .description {
34+
font-size: 0.9em;
35+
color: #666;
36+
margin-top: 2px;
37+
}
38+
</style>
39+
CSS;
40+
41+
$html .= sprintf('<div id="%s">', $elementId);
1342
$name = $element->getName();
1443
$options = $element->getValues();
1544
$values = empty($element->getValue()) ? [] : explode(',', $element->getValue()); // store as CSV in config
1645

1746
foreach ($options as $option) {
1847
$value = $option['value'];
19-
$label = $option['label'];
20-
$checked = in_array($value, $values) ? 'checked' : '';
21-
$html .= '<label style="display:block">';
22-
$html .= sprintf(
23-
'<input type="checkbox" name="%s[]" value="%s" %s /> %s',
48+
$html .= $this->getCheckboxHtml(
2449
$name,
2550
$value,
26-
$checked,
27-
$label
51+
in_array($value, $values),
52+
$option['label'],
53+
array_key_exists('description', $option) ? $option['description'] : ''
2854
);
29-
$html .= '</label>';
3055
}
3156

57+
$html .= '</div>';
58+
return $html;
59+
}
60+
61+
protected function getCheckboxHtml(
62+
string $name,
63+
string $value,
64+
bool $checked,
65+
?string $label = null,
66+
?string $description = null
67+
): string
68+
{
69+
$html = '<div class="form-group">';
70+
$html .= sprintf(
71+
'<input type="checkbox" name="%s[]" value="%s" %s />',
72+
$name,
73+
$value,
74+
$checked ? 'checked' : ''
75+
);
76+
$html .= '<div class="form-content">';
77+
$html .= sprintf('<label>%s</label>',$label ?? $name);
78+
if ($description) {
79+
$html .= sprintf('<span class="description">%s</span>', $description);
80+
}
81+
$html .= '</div>';
82+
$html .= '</div>';
3283
return $html;
3384
}
3485
}

Model/Source/InstantSearchRedirectOptions.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,28 @@ public function toOptionArray()
1717
return [
1818
[
1919
'value' => self::REDIRECT_ON_PAGE_LOAD,
20-
'label' => __('Redirect on page load (if InstantSearch loads with a redirect, immediately take the user to that URL)'),
20+
'label' => __('Redirect on page load'),
21+
'description' => __('If InstantSearch loads search results that include a redirect, immediately take the user to that URL.')
2122
],
2223
[
2324
'value' => self::REDIRECT_ON_SEARCH_AS_YOU_TYPE,
2425
'label' => __('Trigger redirect on "search as you type"'),
26+
'description' =>
27+
__(
28+
'As the user types their query in the %1 widget, matching hits will be retrieved automatically from %2. If a redirect is found for the entered query, this setting will immediately take the user to that URL.',
29+
'<a href="https://www.algolia.com/doc/api-reference/widgets/search-box/js/" target="_blank"><code>searchBox</code></a>',
30+
'<a href="https://www.algolia.com/doc/guides/getting-started/how-algolia-works/" target="_blank">Algolia</a>'
31+
)
2532
],
2633
[
2734
'value' => self::SELECTABLE_REDIRECT,
28-
'label' => __('Display the redirect as a selectable item above search result hits'),
35+
'label' => __('Display redirect as a selectable item'),
36+
'description' => __('If a redirect is found for a search query, display a clickable link to that URL above the search result hits.')
2937
],
3038
[
3139
'value' => self::OPEN_IN_NEW_WINDOW,
32-
'label' => __('Open redirect URL in a new window (applies to clickable links only)'),
40+
'label' => __('Open redirect URL in a new window'),
41+
'description' => __('This setting applies to clickable links only.')
3342
]
3443
];
3544
}

0 commit comments

Comments
 (0)