Repository navigation
1.0.0
Full Changelog: 1.0.0-beta.3...1.0.0
Required Admidio Core adjustment
This plugin version relies on native HTML5 validation for required single-select fields. Admidio 5.0.17 currently renders an empty required single-select so that browsers can treat it as valid.
Before using this version, apply the following small Core adjustment. It affects required normal single-select fields only; multi-selects, optional fields and selects with an explicit firstEntry are unaffected.
1. Use only one empty option
File: src/UI/Presenter/FormPresenter.php, around line 1411 in addSelectBox().
For required fields, do not prepend an additional empty - Please choose - option. The relevant block must be:
} elseif ($optionsAll['showContextDependentFirstEntry']) {
if ($optionsAll['property'] === self::FIELD_REQUIRED) {
// if there is only one entry and a required field than select this entry
if (count($values) === 1) {
$optionsAll['defaultValue'] = array_key_first($values);
}
} else {
array_unshift($valuesArray, array('id' => '', 'value' => ''));
}
}Remove this former else branch inside the FIELD_REQUIRED condition, if it is present:
} else {
array_unshift($valuesArray, array(
'id' => '',
'value' => '- ' . $gL10n->get('SYS_PLEASE_CHOOSE') . ' -'
));
}2. Make the first placeholder option empty
File: themes/simple/templates/sys-template-parts/form.select.tpl, around line 14.
Replace the existing placeholder option:
<option value="placeholder" hidden="hidden" disabled="disabled">{$data.label}</option>with:
{if {array_key_exists key="required" array=$data.attributes} && !$data.multiselect && $data.firstEntry eq ""}
<option value="" {if $data.defaultValue eq ""}selected="selected"{/if} hidden="hidden" disabled="disabled">- {$l10n->get('SYS_PLEASE_CHOOSE')} -</option>
{else}
<option value="placeholder" hidden="hidden" disabled="disabled">{$data.label}</option>
{/if}The required single-select now has exactly one initial option with value="". Therefore, browsers correctly block submission while no valid selection has been made.
This is a temporary workaround for Admidio 5.0.17 until the corresponding Core fix is available.