| @@ -44,10 +44,26 @@ | ||
| 44 | 44 | wp_enqueue_style('ff_choices'); |
| 45 | 45 | $data['attributes']['class'] .= ' ff_has_multi_select'; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - if ($maxSelection = ArrayHelper::get($data, 'settings.max_selection')) { | |
| 48 | + $maxSelection = Helper::resolveMaxSelection($data); | |
| 49 | + | |
| 50 | + if ($maxSelection) { | |
| 49 | 51 | $data['attributes']['data-max_selected_options'] = $maxSelection; |
| 52 | + | |
| 53 | + // Choices.js blocks the pick and draws its own notice, so that notice | |
| 54 | + // is the only wording a visitor ever sees for this limit. Only a | |
| 55 | + // message the site owner actually wrote overrides it — Choices' own | |
| 56 | + // string is translated and carries the count, so a field left on the | |
| 57 | + // global default is better served by it. | |
| 58 | + $rules = ArrayHelper::get($data, 'settings.validation_rules', []); | |
| 59 | + $customMessage = ArrayHelper::isTrue($rules, 'max_selection.global') | |
| 60 | + ? '' | |
| 61 | + : ArrayHelper::get($rules, 'max_selection.message', ''); | |
| 62 | + | |
| 63 | + if ($customMessage) { | |
| 64 | + $data['attributes']['data-max_selection_message'] = $customMessage; | |
| 65 | + } | |
| 50 | 66 | } |
| 51 | 67 | |
| 52 | 68 | $data['attributes']['data-calc_value'] = 0; |
| 53 | 69 | |
| @@ -74,9 +90,9 @@ | ||
| 74 | 90 | if (ArrayHelper::get($data, 'settings.validation_rules.required.value')) { |
| 75 | 91 | $ariaRequired = 'true'; |
| 76 | 92 | } |
| 77 | 93 | |
| 78 | - $ariaLabelledBy = 'label_' . ArrayHelper::get($data, 'attributes.id'); | |
| 94 | + $ariaLabelledBy = esc_attr('label_' . ArrayHelper::get($data, 'attributes.id')); | |
| 79 | 95 | |
| 80 | 96 | $elMarkup = '<select ' . $atts . ' aria-invalid="false" aria-required="' . $ariaRequired . '" aria-labelledby="' . $ariaLabelledBy .'"'.'>' . $options . '</select>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $atts, $options are escaped before being passed in. |
| 81 | 97 | |
| 82 | 98 | $html = $this->buildElementMarkup($elMarkup, $data, $form); |