disable needed angels input if shift is imported

This commit is contained in:
Xu 2023-11-12 19:26:30 +01:00 committed by Igor Scheller
parent 6022d792dc
commit 24f91ce9b5
2 changed files with 8 additions and 5 deletions

View File

@ -195,7 +195,9 @@ function shift_edit_controller()
$angel_types_spinner .= form_spinner( $angel_types_spinner .= form_spinner(
'angeltype_count_' . $angeltype_id, 'angeltype_count_' . $angeltype_id,
$angeltype_name, $angeltype_name,
$needed_angel_types[$angeltype_id] $needed_angel_types[$angeltype_id],
[],
ScheduleShift::whereShiftId($shift->id)->first() ? true : false,
); );
} }

View File

@ -24,21 +24,22 @@ function form_hidden($name, $value)
* @param array $data_attributes * @param array $data_attributes
* @return string * @return string
*/ */
function form_spinner(string $name, string $label, int $value, array $data_attributes = []) function form_spinner(string $name, string $label, int $value, array $data_attributes = [], bool $isDisabled = false)
{ {
$id = 'spinner-' . $name; $id = 'spinner-' . $name;
$attr = ''; $attr = '';
foreach ($data_attributes as $attr_key => $attr_value) { foreach ($data_attributes as $attr_key => $attr_value) {
$attr .= ' data-' . $attr_key . '="' . $attr_value . '"'; $attr .= ' data-' . $attr_key . '="' . $attr_value . '"';
} }
$disabled = $isDisabled ? ' disabled' : '';
return form_element($label, ' return form_element($label, '
<div class="input-group"> <div class="input-group">
<input id="' . $id . '" class="form-control" type="number" min="0" step="1" name="' . $name . '" value="' . $value . '"' . $attr . ' /> <input id="' . $id . '" class="form-control" type="number" min="0" step="1" name="' . $name . '" value="' . $value . '"' . $attr . $disabled . '/>
<button class="btn btn-secondary spinner-down" type="button" data-input-id="' . $id . '"' . $attr . '> <button class="btn btn-secondary spinner-down' . $disabled . '" type="button" data-input-id="' . $id . '"' . $attr . '>
' . icon('dash-lg') . ' ' . icon('dash-lg') . '
</button> </button>
<button class="btn btn-secondary spinner-up" type="button" data-input-id="' . $id . '"' . $attr . '> <button class="btn btn-secondary spinner-up' . $disabled . '" type="button" data-input-id="' . $id . '"' . $attr . '>
' . icon('plus-lg') . ' ' . icon('plus-lg') . '
</button> </button>
</div> </div>