Skip to content

Commit

Permalink
Add copy field
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-alrek committed Feb 28, 2023
1 parent 060ce9f commit 0ac78b4
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Apility/Forms/Concerns/BuildsFormFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use DateTimeInterface;
use InvalidArgumentException;

use Illuminate\Support\Str;
use Illuminate\Support\HtmlString;

trait BuildsFormFields
Expand Down Expand Up @@ -66,14 +67,22 @@ public function withName(string $name)
return $this;
}

public static function copy(string $label)
{
return static::make()
->withName((string) Str::uuid())
->withType('copy')
->withLabel($label);
}

/**
* @param string $type
* @return static
* @throws InvalidArgumentException
*/
public function withType(string $type)
{
if (in_array($type, ['checkbox', 'date', 'email', 'hidden', 'label', 'number', 'password', 'phone', 'select', 'text', 'textarea', 'file', 'image', 'separator'])) {
if (in_array($type, ['checkbox', 'date', 'email', 'hidden', 'label', 'number', 'password', 'phone', 'select', 'text', 'textarea', 'file', 'image', 'separator', 'copy'])) {
$this->attributes['type'] = $type;

return $this;
Expand Down Expand Up @@ -312,13 +321,15 @@ public static function hidden(string $name, $value = null)
public static function label($label)
{
return static::make()
->withName((string) Str::uuid())
->withType('label')
->withLabel($label);
}

public static function separator()
{
return static::make()
->withName((string) Str::uuid())
->withType('separator');
}

Expand Down

0 comments on commit 0ac78b4

Please sign in to comment.