Skip to content

Commit

Permalink
New: Include Livewire child component
Browse files Browse the repository at this point in the history
New: Auto select single array value
Fix: view() not available for Array or KeyVal fields
  • Loading branch information
tanthammar committed Aug 12, 2020
1 parent e885867 commit f284f4f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 17 deletions.
6 changes: 4 additions & 2 deletions resources/views/form-layout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
@if(filled($field))
<div class="sm:col-span-{{ $field->colspan ?? 6 }}">
@if($field->view)
@include($field->view)
@include($field->view)
@elseif($field->livewireComponent)
@livewire($field->livewireComponent, $field->livewireParams)
@else
@include('tall-forms::fields.' . $field->type)
@include('tall-forms::fields.' . $field->type)
@endif
</div>
@endif
Expand Down
13 changes: 0 additions & 13 deletions src/BaseField.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class BaseField
protected $placeholder;
protected $help;
protected $rules;
protected $view;
protected $prefix;
protected $icon;
protected $colspan;
Expand Down Expand Up @@ -172,18 +171,6 @@ public function rules($rules): BaseField
return $this;
}


/**
* Display a custom view instad of the default field view
* @param string $view
* @return $this
*/
public function view(string $view): BaseField
{
$this->view = $view;
return $this;
}

/**
* Default 6 of 6 columns
* @param int $width
Expand Down
21 changes: 21 additions & 0 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class Field extends BaseField
protected $array_fields = [];
protected $keyval_fields = [];
protected $array_sortable = false;
protected $view;
protected $livewireComponent;
protected $livewireParams;


public function __construct($label, $name)
Expand Down Expand Up @@ -57,4 +60,22 @@ public function sortable(): Field
$this->array_sortable = true;
return $this;
}

/**
* Display a custom view instad of the default field view
* @param string $view
* @return $this
*/
public function view(string $view): BaseField
{
$this->view = $view;
return $this;
}

public function livewireComponent(string $component, array $params = []): BaseField
{
$this->livewireComponent = $component;
$this->livewireParams = $params;
return $this;
}
}
2 changes: 0 additions & 2 deletions src/FormComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ public function errorMessage($message)

public function success()
{
// $this->form_data['password'] = bcrypt($this->form_data['password']);
// \App\Models\User::create($this->form_data);
($this->action == 'update')
? $this->model->update($this->form_data)
: $this->create($this->form_data);
Expand Down
7 changes: 7 additions & 0 deletions src/Traits/HandlesArrays.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@ public function arrayRemove($field_name, $key)
unset($this->form_data[$field_name][$key]);
$this->form_data[$field_name] = array_values($this->form_data[$field_name]);
}

public function autoSelectSingleArrayValue(string $arrayName, string $field)
{
if (count($this->$arrayName) === 1) {
$this->form_data[$field] = array_values($this->$arrayName);
}
}
}

0 comments on commit f284f4f

Please sign in to comment.