New checkboxes fieldtype

This commit is contained in:
Ryan Scherler
2020-12-21 14:59:01 -08:00
parent 6c15b204e2
commit d64e70acef
5 changed files with 54 additions and 25 deletions
@@ -0,0 +1,7 @@
<ol>
@foreach ($options as $option)
<li>
{{ $option->render() }}
</li>
@endforeach
</ol>
+1 -1
View File
@@ -1,5 +1,5 @@
<fieldset class="border rounded border-grey-100 p-4 md:px-6">
<legend class="text-sm leading-tight font-semibold cursor-pointer px-2">
<legend class="text-sm leading-tight font-semibold px-2">
{{ __($legend) }}
</legend>
<x-filament::fields :fields="$fields" :class="$class" />
+25
View File
@@ -5,9 +5,34 @@ namespace Filament\Fields;
use Illuminate\Support\Str;
class BaseField {
public $model;
public $id;
protected $enabled = true;
protected $view;
public function __construct($model)
{
$this->model = $model;
$this->id = Str::slug($model);
}
/**
* @return static
*/
public static function make(string $model): self
{
return new static($model);
}
/**
* @return static
*/
public function id($id): self
{
$this->id = $id;
return $this;
}
/**
* @return static
*/
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace Filament\Fields;
use Filament\Fields\Checkbox;
class Checkboxes extends BaseField {
public $options = [];
/**
* @return static
*/
public function options(array $options): self
{
foreach ($options as $key => $value) {
$this->options[] = Checkbox::make($this->model.'.'.$key)->label($value);
}
return $this;
}
}
-24
View File
@@ -3,27 +3,12 @@
namespace Filament\Fields;
class Field extends BaseField {
public $model;
public $modelDirective = 'wire:model.defer';
public $value;
public $id;
public $label;
public $hint;
public $help;
public $extraAttributes = [];
public function __construct($model)
{
$this->model = $this->id = $model;
}
/**
* @return static
*/
public static function make(string $model): self
{
return new static($model);
}
/**
* @return static
@@ -43,15 +28,6 @@ class Field extends BaseField {
return $this;
}
/**
* @return static
*/
public function id($id): self
{
$this->id = $id;
return $this;
}
/**
* @return static
*/