make reactive custom field options
Hello everyone, i have custom form field with options
S3Uploader
and standart field in same form
i want reactive change bucket attribute dependend on $state of Select::make('bucket'), how i may make this.
S3Uploader::make('url')
->folder('music')
->bucket(fn() => $form->bucket ?? 'private')
->entityId(fn()=>$form->getRecord()?->id ?? $id)
->columnSpanFull()
S3Uploader::make('url')
->folder('music')
->bucket(fn() => $form->bucket ?? 'private')
->entityId(fn()=>$form->getRecord()?->id ?? $id)
->columnSpanFull()
class S3Uploader extends Field
{
use HasHelperText;
protected string $view = 'forms.components.s3-uploader';
protected ?bool $isLive = true;
protected string | \Closure | null $bucket = 's3_public';
protected string | \Closure | null $folder = '/';
protected string | \Closure $entityId;
public function updateBucketType($bucketType): void
{
$this->bucket = $bucketType;
}
public function bucket($bucket) : static
{
$this->bucket = $bucket;
return $this;
}
public function entityId($id) : static
{
$this->entityId = $id;
return $this;
}
public function getEntityId() : string
{
return $this->evaluate($this->entityId);
}
public function getBucket(): ?string
{
return $this->evaluate($this->bucket);
}
public function folder($folder) : static
{
$this->folder = $folder;
return $this;
}
public function getFolder(): ?string
{
return $this->evaluate($this->folder);
}
}
class S3Uploader extends Field
{
use HasHelperText;
protected string $view = 'forms.components.s3-uploader';
protected ?bool $isLive = true;
protected string | \Closure | null $bucket = 's3_public';
protected string | \Closure | null $folder = '/';
protected string | \Closure $entityId;
public function updateBucketType($bucketType): void
{
$this->bucket = $bucketType;
}
public function bucket($bucket) : static
{
$this->bucket = $bucket;
return $this;
}
public function entityId($id) : static
{
$this->entityId = $id;
return $this;
}
public function getEntityId() : string
{
return $this->evaluate($this->entityId);
}
public function getBucket(): ?string
{
return $this->evaluate($this->bucket);
}
public function folder($folder) : static
{
$this->folder = $folder;
return $this;
}
public function getFolder(): ?string
{
return $this->evaluate($this->folder);
}
}
Select::make('bucket')
->required()
->live()
->afterStateUpdated(
function($state, callable $set) use ($form) {
//some code here?
}
)->options(['public','private'])
Select::make('bucket')
->required()
->live()
->afterStateUpdated(
function($state, callable $set) use ($form) {
//some code here?
}
)->options(['public','private'])
1 Reply
You can't as far as I am aware. You could create two fields however, one is priate and one is public. With a ToggleButtons field to select if it is private or public