formField() evals allow_empty

This commit is contained in:
Uwe Steinmann 2023-02-28 11:31:31 +01:00
parent 245092bb10
commit 13a0646698
2 changed files with 8 additions and 0 deletions

View File

@ -1138,17 +1138,21 @@ background-image: linear-gradient(to bottom, #882222, #111111);;
} elseif(is_array($value)) { } elseif(is_array($value)) {
switch($value['element']) { switch($value['element']) {
case 'select': case 'select':
$allowempty = empty($value['allow_empty']) ? false : $value['allow_empty'];
echo '<select'. echo '<select'.
(!empty($value['id']) ? ' id="'.$value['id'].'"' : ''). (!empty($value['id']) ? ' id="'.$value['id'].'"' : '').
(!empty($value['name']) ? ' name="'.$value['name'].'"' : ''). (!empty($value['name']) ? ' name="'.$value['name'].'"' : '').
(!empty($value['class']) ? ' class="'.$value['class'].'"' : ''). (!empty($value['class']) ? ' class="'.$value['class'].'"' : '').
(!empty($value['placeholder']) ? ' data-placeholder="'.$value['placeholder'].'"' : ''). (!empty($value['placeholder']) ? ' data-placeholder="'.$value['placeholder'].'"' : '').
($allowempty ? ' data-allow-clear="true"' : '').
(!empty($value['multiple']) ? ' multiple' : ''); (!empty($value['multiple']) ? ' multiple' : '');
if(!empty($value['attributes']) && is_array($value['attributes'])) if(!empty($value['attributes']) && is_array($value['attributes']))
foreach($value['attributes'] as $a) foreach($value['attributes'] as $a)
echo ' '.$a[0].'="'.$a[1].'"'; echo ' '.$a[0].'="'.$a[1].'"';
echo ">"; echo ">";
if(isset($value['options']) && is_array($value['options'])) { if(isset($value['options']) && is_array($value['options'])) {
if($allowempty)
echo "<option value=\"\"></option>";
foreach($value['options'] as $val) { foreach($value['options'] as $val) {
if(is_string($val)) { if(is_string($val)) {
echo '<optgroup label="'.$val.'">'; echo '<optgroup label="'.$val.'">';

View File

@ -1122,17 +1122,21 @@ background-image: linear-gradient(to bottom, #882222, #111111);;
} elseif(is_array($value)) { } elseif(is_array($value)) {
switch($value['element']) { switch($value['element']) {
case 'select': case 'select':
$allowempty = empty($value['allow_empty']) ? false : $value['allow_empty'];
echo '<select'. echo '<select'.
(!empty($value['id']) ? ' id="'.$value['id'].'"' : ''). (!empty($value['id']) ? ' id="'.$value['id'].'"' : '').
(!empty($value['name']) ? ' name="'.$value['name'].'"' : ''). (!empty($value['name']) ? ' name="'.$value['name'].'"' : '').
(empty($value['class']) ? ' class="form-control"' : ' class="form-control '.$value['class'].'"'). (empty($value['class']) ? ' class="form-control"' : ' class="form-control '.$value['class'].'"').
(!empty($value['placeholder']) ? ' data-placeholder="'.$value['placeholder'].'"' : ''). (!empty($value['placeholder']) ? ' data-placeholder="'.$value['placeholder'].'"' : '').
($allowempty ? ' data-allow-clear="true"' : '').
(!empty($value['multiple']) ? ' multiple' : ''); (!empty($value['multiple']) ? ' multiple' : '');
if(!empty($value['attributes']) && is_array($value['attributes'])) if(!empty($value['attributes']) && is_array($value['attributes']))
foreach($value['attributes'] as $a) foreach($value['attributes'] as $a)
echo ' '.$a[0].'="'.$a[1].'"'; echo ' '.$a[0].'="'.$a[1].'"';
echo ">"; echo ">";
if(isset($value['options']) && is_array($value['options'])) { if(isset($value['options']) && is_array($value['options'])) {
if($allowempty)
echo "<option value=\"\"></option>";
foreach($value['options'] as $val) { foreach($value['options'] as $val) {
if(is_string($val)) { if(is_string($val)) {
echo '<optgroup label="'.$val.'">'; echo '<optgroup label="'.$val.'">';