Add new form field type called "number"
This commit is contained in:
parent
dc9acd472a
commit
60de683cb8
|
|
@ -7392,6 +7392,9 @@ label {
|
|||
.form-group.checkbox-field {
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
.form-group.number-field > .form-control {
|
||||
text-align: right;
|
||||
}
|
||||
.form-group.checkbox-align {
|
||||
padding-left: 23px;
|
||||
margin-top: -5px;
|
||||
|
|
|
|||
|
|
@ -129,6 +129,10 @@ label {
|
|||
padding-bottom: 5px;
|
||||
}
|
||||
|
||||
&.number-field {
|
||||
> .form-control { text-align: right; }
|
||||
}
|
||||
|
||||
&.checkbox-align {
|
||||
padding-left: 23px;
|
||||
margin-top: -5px;
|
||||
|
|
|
|||
|
|
@ -533,9 +533,11 @@ class Form extends WidgetBase
|
|||
|
||||
/*
|
||||
* Boolean fields (checkbox, switch) won't be present value FALSE
|
||||
* Number fields should be converted to integers
|
||||
*/
|
||||
foreach ($this->allFields as $field) {
|
||||
if ($field->type != 'switch' && $field->type != 'checkbox')
|
||||
|
||||
if (!in_array($field->type, ['switch', 'checkbox', 'number']))
|
||||
continue;
|
||||
|
||||
/*
|
||||
|
|
@ -544,6 +546,7 @@ class Form extends WidgetBase
|
|||
$columnParts = Str::evalHtmlArray($field->columnName);
|
||||
$columnDotted = implode('.', $columnParts);
|
||||
$columnValue = array_get($data, $columnDotted, 0);
|
||||
if ($field->type == 'number') $columnValue = (int) $columnValue;
|
||||
array_set($data, $columnDotted, $columnValue);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
<!-- Number -->
|
||||
<?php if ($this->previewMode): ?>
|
||||
<span class="form-control"><?= $field->value ? e($field->value) : ' ' ?></span>
|
||||
<?php else: ?>
|
||||
<input
|
||||
type="number"
|
||||
name="<?= $field->getName() ?>"
|
||||
id="<?= $field->getId() ?>"
|
||||
value="<?= e($field->value) ?>"
|
||||
placeholder="<?= e(trans($field->placeholder)) ?>"
|
||||
class="form-control"
|
||||
autocomplete="off"
|
||||
maxlength="255"
|
||||
<?= HTML::attributes($field->attributes) ?>
|
||||
/>
|
||||
<?php endif ?>
|
||||
Loading…
Reference in New Issue