mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
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:
parent
14c140c520
commit
955307bdfe
@ -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();
|
||||
}
|
||||
}
|
@ -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 !!}':
|
||||
|
Loading…
x
Reference in New Issue
Block a user