← All changes
|
app/Services/FormBuilder/Components/Checkable.php
+22
-2
6.2.12
→
6.2.15
View file →
| @@ -158,11 +158,31 @@ | ||
| 158 | 158 | $fieldName = str_replace(['[', ']'], '', $data['attributes']['name']); |
| 159 | 159 | $otherInputName = $fieldName . '__ff_other_input__'; |
| 160 | 160 | $otherValue = ''; |
| 161 | 161 | |
| 162 | + // Defaulted like the sibling reads above: forms saved before this | |
| 163 | + // setting existed would otherwise fall through to the field's | |
| 164 | + // "This field is required", which is wrong on an optional field. | |
| 165 | + $otherRequiredMessage = trim((string) ArrayHelper::get( | |
| 166 | + $data, | |
| 167 | + 'settings.other_option_required_message', | |
| 168 | + __('Please specify a value for the selected "Other" option', 'fluentform') | |
| 169 | + )); | |
| 170 | + | |
| 171 | + // An "Other" that is already selected (configured or dynamic | |
| 172 | + // default) must render with its input visible and required — | |
| 173 | + // otherwise the field is mandatory but invisible and the form | |
| 174 | + // cannot be submitted at all. | |
| 175 | + $otherIsSelected = in_array($option['value'], $defaultValues); | |
| 176 | + $wrapperDisplay = $otherIsSelected ? '' : 'display: none; '; | |
| 177 | + $otherAriaRequired = $otherIsSelected ? " aria-required='true'" : ''; | |
| 178 | + | |
| 162 | 179 | $marginTop = $hasImageOption ? '20px' : '8px'; |
| 163 | - $otherInputHtml .= "<div class='ff-other-input-wrapper' style='display: none; margin-top: {$marginTop};' data-field='{$fieldName}'>"; | |
| 164 | - $otherInputHtml .= "<input type='text' name='" . esc_attr($otherInputName) . "' class='ff-el-form-control' placeholder='" . esc_attr($otherPlaceholder) . "' value='" . esc_attr($otherValue) . "'>"; | |
| 180 | + $otherInputHtml .= "<div class='ff-other-input-wrapper' style='{$wrapperDisplay}margin-top: {$marginTop};' data-field='" . esc_attr($fieldName) . "' data-required-message='" . esc_attr($otherRequiredMessage) . "'>"; | |
| 181 | + // The id is what the validator points aria-describedby at when the | |
| 182 | + // free text is required but empty. | |
| 183 | + $otherInputId = $this->getUniqueid('ff_other_' . $fieldName); | |
| 184 | + $otherInputHtml .= "<input type='text' id='" . esc_attr($otherInputId) . "' name='" . esc_attr($otherInputName) . "' class='ff-el-form-control'{$otherAriaRequired} placeholder='" . esc_attr($otherPlaceholder) . "' value='" . esc_attr($otherValue) . "'>"; | |
| 165 | 185 | $otherInputHtml .= "</div>"; |
| 166 | 186 | } |
| 167 | 187 | |
| 168 | 188 | $elMarkup .= '</div>'; |