Skip to content

Commit

Permalink
Button name attribute is no longer required. Added jsSet and jsKey at…
Browse files Browse the repository at this point in the history
…tributes to Select input which allows you to add additional properties to Select options which can be often used with JavaScript dataset. Minor adjustments and to CSS.
  • Loading branch information
BJNSTNKVC committed Nov 13, 2022
1 parent 3c8e420 commit a3bfc26
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/View/Components/Form/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Button extends Component
*
* @return void
*/
public function __construct($name, $id = null, $title = null, $link = null, $borderRadius = null)
public function __construct($name = null, $id = null, $title = null, $link = null, $borderRadius = null)
{
$this->name = $name;
$this->id = $id ?: Str::camel($name);
Expand Down
15 changes: 14 additions & 1 deletion src/View/Components/Form/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ class Select extends Component
*/
public $modelValue;

/**
* A Model JavaScript data attribute.
*/
public $jsSet;

/**
* A Model JavaScript key.
*/
public $jsKey;

/**
* Select component placeholder.
*/
Expand Down Expand Up @@ -93,14 +103,17 @@ class Select extends Component
*
* @return void
*/
public function __construct($name, $id = null, $title = null, $values = null, $model = null, $modelKey = null, $modelValue = null, $placeholder = null, $label = null, $labelType = null, $border = null, $borderRadius = null, $invalidatedTitle = null, $showIcon = null, $icon = null, $default = null) {
public function __construct($name, $id = null, $title = null, $values = null, $model = null, $modelKey = null, $modelValue = null, $jsSet = null, $jsKey = null, $placeholder = null, $label = null, $labelType = null, $border = null, $borderRadius = null, $invalidatedTitle = null, $showIcon = null, $icon = null, $default = null)
{
$this->name = Str::slug($name, '_');
$this->id = $id ?: $this->name;
$this->title = $title ?: Str::title($name);
$this->values = $this->toArray($values) ?: [];
$this->model = $model;
$this->modelKey = $modelKey ?: 'id';
$this->modelValue = $modelValue;
$this->jsSet = 'data-' . $jsSet . '=';
$this->jsKey = $jsKey;
$this->placeholder = $placeholder;
$this->label = $label;
$this->labelType = $labelType ?: config('form_components.label_type');
Expand Down
3 changes: 2 additions & 1 deletion src/resources/views/components/form/select.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
@endforeach
@endif


@if($model)
@foreach ($model as $m)
<option value="{{ $m[$modelKey] }}" {{ Str::is($m[$modelValue], $default) && is_null(old($name)) ? 'selected' : '' }} {{ old($name) == $m[$modelKey] ? 'selected' : '' }}>{{ $m[$modelValue] }}</option>
<option @if($jsKey) {{ $jsSet . $m->$jsKey }} @endif value="{{ $m->$modelKey }}" {{ Str::is($m->$modelValue, $default) && is_null(old($name)) ? 'selected' : '' }} {{ old($name) == $m->$modelKey ? 'selected' : '' }}>{{ $m->$modelValue }}</option>
@endforeach
@endif
</select>
Expand Down

0 comments on commit a3bfc26

Please sign in to comment.