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
This commit is contained in:
Christopher Di Carlo 2019-05-18 01:10:04 -04:00 committed by David Bomba
parent 14c140c520
commit 955307bdfe
2 changed files with 13 additions and 3 deletions

View File

@ -15,12 +15,14 @@ class SimpleSelectComponent implements Htmlable
protected $module; protected $module;
protected $secondaryItemLabel; protected $secondaryItemLabel;
protected $selectId; 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->entityType = $entityType;
$this->items = $items; $this->items = $items;
$this->itemLabel = $itemLabel; $this->itemLabel = $itemLabel;
$this->fieldLabel = $fieldLabel; $this->fieldLabel = $fieldLabel;
$this->defaultValue = $defaultValue;
$this->module = $module; $this->module = $module;
$this->secondaryItemLabel = $secondaryItemLabel; $this->secondaryItemLabel = $secondaryItemLabel;
@ -40,6 +42,7 @@ class SimpleSelectComponent implements Htmlable
'secondaryItemLabel' => $this->secondaryItemLabel, 'secondaryItemLabel' => $this->secondaryItemLabel,
'fieldLabel' => mtrans($this->module, $this->fieldLabel), 'fieldLabel' => mtrans($this->module, $this->fieldLabel),
'selectId' => $this->selectId, 'selectId' => $this->selectId,
'defaultValue' => $this->defaultValue,
])->render(); ])->render();
} }
} }

View File

@ -1,7 +1,7 @@
{!! Former::select($selectId) {!! Former::select($selectId)
->addOption('', '') ->addOption('', '')
->fromQuery($items, $itemLabel, 'public_id') ->fromQuery($items, $itemLabel, ($entityType == ENTITY_USER ? 'id' : 'public_id'))
->label($fieldLabel) !!} ->label($fieldLabel) !!}
@push('component_scripts') @push('component_scripts')
@ -12,6 +12,7 @@
var items = {!! $items !!}; var items = {!! $items !!};
var secondaryItemLabel = '{!! $secondaryItemLabel !!}'; var secondaryItemLabel = '{!! $secondaryItemLabel !!}';
var secondaryItemLabelType = '{!! empty($secondaryItemLabelType) ? "field" : $secondaryItemLabelType !!}'; var secondaryItemLabelType = '{!! empty($secondaryItemLabelType) ? "field" : $secondaryItemLabelType !!}';
var defaultValue = {!! $defaultValue !!};
var itemMap = {}; var itemMap = {};
var $itemSelect = $('select#{!! $selectId !!}'); var $itemSelect = $('select#{!! $selectId !!}');
@ -20,7 +21,13 @@
var entity = items[i]; var entity = items[i];
var itemName = ''; var itemName = '';
switch(entityType) {
case '{!! ENTITY_USER !!}':
itemMap[entity.id] = entity;
break;
default:
itemMap[entity.public_id] = entity; itemMap[entity.public_id] = entity;
}
switch(entityType) { switch(entityType) {
case '{!! ENTITY_CLIENT !!}': case '{!! ENTITY_CLIENT !!}':