From 955307bdfe5ad24673c90d04a509038a1d1836a2 Mon Sep 17 00:00:00 2001 From: Christopher Di Carlo Date: Sat, 18 May 2019 01:10:04 -0400 Subject: [PATCH] Added ability to set default value (#2835) * Added ability to set default value * Fixed bug for case when user is the entity * Removed debugging code * Removed debugging code --- app/Http/ViewComponents/SimpleSelectComponent.php | 5 ++++- resources/views/components/simple_select.blade.php | 11 +++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/Http/ViewComponents/SimpleSelectComponent.php b/app/Http/ViewComponents/SimpleSelectComponent.php index bd88e74df131..973f11ed9443 100644 --- a/app/Http/ViewComponents/SimpleSelectComponent.php +++ b/app/Http/ViewComponents/SimpleSelectComponent.php @@ -15,12 +15,14 @@ class SimpleSelectComponent implements Htmlable protected $module; protected $secondaryItemLabel; protected $selectId; + protected $defaultValue; - public function __construct($entityType, $items, $itemLabel, $fieldLabel, $secondaryItemLabel = null, $module = null, $selectId = null) { + public function __construct($entityType, $items, $itemLabel, $fieldLabel, $defaultValue = null, $secondaryItemLabel = null, $module = null, $selectId = null) { $this->entityType = $entityType; $this->items = $items; $this->itemLabel = $itemLabel; $this->fieldLabel = $fieldLabel; + $this->defaultValue = $defaultValue; $this->module = $module; $this->secondaryItemLabel = $secondaryItemLabel; @@ -40,6 +42,7 @@ class SimpleSelectComponent implements Htmlable 'secondaryItemLabel' => $this->secondaryItemLabel, 'fieldLabel' => mtrans($this->module, $this->fieldLabel), 'selectId' => $this->selectId, + 'defaultValue' => $this->defaultValue, ])->render(); } } \ No newline at end of file diff --git a/resources/views/components/simple_select.blade.php b/resources/views/components/simple_select.blade.php index 1114a03fbf97..950ce88a854e 100644 --- a/resources/views/components/simple_select.blade.php +++ b/resources/views/components/simple_select.blade.php @@ -1,7 +1,7 @@ {!! Former::select($selectId) ->addOption('', '') - ->fromQuery($items, $itemLabel, 'public_id') + ->fromQuery($items, $itemLabel, ($entityType == ENTITY_USER ? 'id' : 'public_id')) ->label($fieldLabel) !!} @push('component_scripts') @@ -12,6 +12,7 @@ var items = {!! $items !!}; var secondaryItemLabel = '{!! $secondaryItemLabel !!}'; var secondaryItemLabelType = '{!! empty($secondaryItemLabelType) ? "field" : $secondaryItemLabelType !!}'; + var defaultValue = {!! $defaultValue !!}; var itemMap = {}; var $itemSelect = $('select#{!! $selectId !!}'); @@ -20,7 +21,13 @@ var entity = items[i]; var itemName = ''; - itemMap[entity.public_id] = entity; + switch(entityType) { + case '{!! ENTITY_USER !!}': + itemMap[entity.id] = entity; + break; + default: + itemMap[entity.public_id] = entity; + } switch(entityType) { case '{!! ENTITY_CLIENT !!}':