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 $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();
}
}

View File

@ -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 !!}':