class Field implements Renderable

Class Field.

Traits

Macroable

Constants

FILE_DELETE_FLAG

FILE_SORT_FLAG

Properties

array|Closure $creationRules

The validation rules for creation.

array|Closure $updateRules

The validation rules for updates.

bool $isJsonType
protected array|string $id

Element id.

protected mixed $value

Element value.

protected mixed $data

Data of all original columns of value.

protected mixed $original

Field original value.

protected mixed $default

Field default value.

protected string $label

Element label.

protected string|array $column

Column name.

protected string $elementName

Form element name.

protected array $elementClass

Form element classes.

protected array $variables

Variables of elements.

protected array $options

Options for specify elements.

protected array $checked

Checked for specify elements.

protected array|Closure $rules

Validation rules.

protected Closure $validator
protected array $validationMessages

Validation messages.

protected array $attributes

Element attributes.

protected Form $form

Parent form.

protected string $view

View for field to render.

protected array $help

Help block.

protected mixed $errorKey

Key for errors.

protected string|array $placeholder

Placeholder for this field.

protected bool $showHelp
protected array $width

Width for label and field.

protected bool $horizontal

If the form horizontal layout.

protected Closure $customFormat

column data format.

protected bool $display
protected array $labelClass
protected array $groupClass
protected Closure $callback

Methods

__construct($column = '', array $arguments = [])

Field constructor.

$this
setElementName(string $name)

Set form element name.

void
fill(array $data)

Fill data to the field.

$this
customFormat(Closure $call)

custom format form column data when edit.

void
setOriginal(array $data)

Set original value to the field.

$this
setForm(Form $form = null)

No description

$this
setWidth(int $field = 8, int $label = 2)

Set width for field and label.

$this
options(array $options = [])

Set the field options.

$this
checked(array $checked = [])

Set the field option checked.

$this
rules(array $rules = [], array $messages = [])

Set the validation rules for the field.

$this
updateRules(array|callable $rules = [], array $messages = [])

Set the update validation rules for the field.

$this
creationRules(array|callable $rules = [], array $messages = [])

Set the creation validation rules for the field.

array|mixed
getValidationMessages()

Get validation messages for the field.

$this
setValidationMessages(string $key, array $messages)

Set validation messages for column.

$this
validator(callable $validator)

Set field validator.

string
getErrorKey()

Get key for error message.

$this
setErrorKey(string $key)

Set key for error message.

mixed
value(null $value = null)

Set or get value of the field.

$this
data(array $data = null)

Set or get data.

$this
default($default)

Set default value for field.

mixed
getDefault()

Get default value.

$this
help(string $text = '', string $icon = 'fa-info-circle')

Set help block for current field.

string|array
column()

Get column of the field.

string
label()

Get label of the field.

mixed
original()

Get original value of the field.

bool|Validator|mixed
getValidator(array $input)

Get validator for this field.

$this
attribute(array|string $attribute, mixed $value = null)

Add html attributes to elements.

$this
style(string $attr, string $value)

Set Field style.

$this
width(string $width)

Set Field width.

$this
autofocus()

Set the field automatically get focus.

$this
readonly()

Set the field as readonly mode.

$this
disable()

Set field as disabled.

$this
placeholder(string $placeholder = '')

Set field placeholder.

string
getPlaceholder()

Get placeholder.

mixed
prepare($value)

Prepare for a field value before update or insert.

$this
disableHorizontal()

No description

array
getViewElementClasses()

No description

array
getElementClass()

Get element class.

$this
setElementClass(string|array $class)

Set form element class.

$this
addElementClass($class)

Add the element class.

$this
removeElementClass($class)

Remove element class.

$this
resetElementClassName(string $className, string $resetClassName)

reset field className.

string
getLabelClass()

No description

setLabelClass(array $labelClass)

No description

array
variables()

Get the view variables of this field.

string
getView()

Get view of this field.

string
setView(string $view)

Set view of current field.

string
getType()

No description

$this
setDisplay(bool $display)

To set this field should render or not.

with(Closure $callback)

No description

Factory|View|string
render()

Render this filed.

string
__toString()

No description

string
getRules()

Get field validation rules.

array|mixed|string
formatName(string $column)

Format the name of the field.

array
skeleton()

No description

mixed
formatColumn(string $column = '')

Format the field column name.

string|array
formatId(string|array $column)

Format the field element id.

string
formatLabel(array $arguments = [])

Format the label value.

formatValue()

Format value by passing custom formater.

addRequiredAttribute(array $rules)

Add required attribute to current field if has required rule, except file and image fields.

addRequiredAttributeFromRules()

If has required rule, add required attribute to this field.

array
formatRules(array|string $rules)

Format validation rules.

array|Closure
mergeRules(string|array|Closure $input, string|array $original)

No description

void
removeRule(string $rule)

Remove a specific rule by keyword.

array
sanitizeInput(array $input, string $column)

Sanitize input data.

string
formatAttributes()

Format the field attributes.

mixed
getElementClassString()

Get element class string.

string|array
getElementClassSelector()

Get element class selector.

string
getGroupClass(bool $default = false)

Get element class.

setGroupClass(string|array $class)

Set form group class.

addVariables(array $variables = [])

Add variables to field view.

bool
shouldRender()

If this field should render.

Details

at line 224
__construct($column = '', array $arguments = [])

Field constructor.

Parameters

$column
array $arguments

at line 240
$this setElementName(string $name)

Set form element name.

Parameters

string $name

Return Value

$this

at line 254
void fill(array $data)

Fill data to the field.

Parameters

array $data

Return Value

void

at line 278
$this customFormat(Closure $call)

custom format form column data when edit.

Parameters

Closure $call

Return Value

$this

at line 292
void setOriginal(array $data)

Set original value to the field.

Parameters

array $data

Return Value

void

at line 310
$this setForm(Form $form = null)

No description

Parameters

Form $form

Return Value

$this

at line 325
$this setWidth(int $field = 8, int $label = 2)

Set width for field and label.

Parameters

int $field
int $label

Return Value

$this

at line 342
$this options(array $options = [])

Set the field options.

Parameters

array $options

Return Value

$this

at line 360
$this checked(array $checked = [])

Set the field option checked.

Parameters

array $checked

Return Value

$this

at line 379
$this rules(array $rules = [], array $messages = [])

Set the validation rules for the field.

Parameters

array $rules
array $messages

Return Value

$this

at line 396
$this updateRules(array|callable $rules = [], array $messages = [])

Set the update validation rules for the field.

Parameters

array|callable $rules
array $messages

Return Value

$this

at line 413
$this creationRules(array|callable $rules = [], array $messages = [])

Set the creation validation rules for the field.

Parameters

array|callable $rules
array $messages

Return Value

$this

at line 427
array|mixed getValidationMessages()

Get validation messages for the field.

Return Value

array|mixed

at line 450
$this setValidationMessages(string $key, array $messages)

Set validation messages for column.

Parameters

string $key
array $messages

Return Value

$this

at line 464
$this validator(callable $validator)

Set field validator.

Parameters

callable $validator

Return Value

$this

at line 476
string getErrorKey()

Get key for error message.

Return Value

string

at line 488
$this setErrorKey(string $key)

Set key for error message.

Parameters

string $key

Return Value

$this

at line 502
mixed value(null $value = null)

Set or get value of the field.

Parameters

null $value

Return Value

mixed

at line 518
$this data(array $data = null)

Set or get data.

Parameters

array $data

Return Value

$this

at line 536
$this default($default)

Set default value for field.

Parameters

$default

Return Value

$this

at line 548
mixed getDefault()

Get default value.

Return Value

mixed

at line 565
$this help(string $text = '', string $icon = 'fa-info-circle')

Set help block for current field.

Parameters

string $text
string $icon

Return Value

$this

at line 577
string|array column()

Get column of the field.

Return Value

string|array

at line 587
string label()

Get label of the field.

Return Value

string

at line 597
mixed original()

Get original value of the field.

Return Value

mixed

at line 609
bool|Validator|mixed getValidator(array $input)

Get validator for this field.

Parameters

array $input

Return Value

bool|Validator|mixed

at line 650
$this attribute(array|string $attribute, mixed $value = null)

Add html attributes to elements.

Parameters

array|string $attribute
mixed $value

Return Value

$this

at line 670
$this style(string $attr, string $value)

Set Field style.

Parameters

string $attr
string $value

Return Value

$this

at line 682
$this width(string $width)

Set Field width.

Parameters

string $width

Return Value

$this

at line 692
$this autofocus()

Set the field automatically get focus.

Return Value

$this

at line 702
$this readonly()

Set the field as readonly mode.

Return Value

$this

at line 712
$this disable()

Set field as disabled.

Return Value

$this

at line 724
$this placeholder(string $placeholder = '')

Set field placeholder.

Parameters

string $placeholder

Return Value

$this

at line 736
string getPlaceholder()

Get placeholder.

Return Value

string

at line 750
mixed prepare($value)

Prepare for a field value before update or insert.

Parameters

$value

Return Value

mixed

at line 758
$this disableHorizontal()

No description

Return Value

$this

at line 768
array getViewElementClasses()

No description

Return Value

array

at line 790
array getElementClass()

Get element class.

Return Value

array

at line 802
$this setElementClass(string|array $class)

Set form element class.

Parameters

string|array $class

Return Value

$this

at line 816
$this addElementClass($class)

Add the element class.

Parameters

$class

Return Value

$this

at line 832
$this removeElementClass($class)

Remove element class.

Parameters

$class

Return Value

$this

at line 857
$this resetElementClassName(string $className, string $resetClassName)

reset field className.

Parameters

string $className
string $resetClassName

Return Value

$this

at line 869
string getLabelClass()

No description

Return Value

string

at line 879
Field setLabelClass(array $labelClass)

No description

Parameters

array $labelClass

Return Value

Field

at line 891
array variables()

Get the view variables of this field.

Return Value

array

at line 916
string getView()

Get view of this field.

Return Value

string

at line 934
string setView(string $view)

Set view of current field.

Parameters

string $view

Return Value

string

at line 941
string getType()

No description

Return Value

string

at line 954
$this setDisplay(bool $display)

To set this field should render or not.

Parameters

bool $display

Return Value

$this

at line 966
Field with(Closure $callback)

No description

Parameters

Closure $callback

Return Value

Field

at line 978
Factory|View|string render()

Render this filed.

Return Value

Factory|View|string

at line 995
string __toString()

No description

Return Value

string

Exceptions

Throwable

at line 1005
string getRules()

Get field validation rules.

Return Value

string

at line 1051
array|mixed|string formatName(string $column)

Format the name of the field.

Parameters

string $column

Return Value

array|mixed|string

at line 1085
array skeleton()

No description

Return Value

array

at line 1097
protected mixed formatColumn(string $column = '')

Format the field column name.

Parameters

string $column

Return Value

mixed

at line 1115
protected string|array formatId(string|array $column)

Format the field element id.

Parameters

string|array $column

Return Value

string|array

at line 1127
protected string formatLabel(array $arguments = [])

Format the label value.

Parameters

array $arguments

Return Value

string

at line 1139
protected formatValue()

Format value by passing custom formater.

at line 1152
protected addRequiredAttribute(array $rules)

Add required attribute to current field if has required rule, except file and image fields.

Parameters

array $rules

at line 1162
protected addRequiredAttributeFromRules()

If has required rule, add required attribute to this field.

at line 1183
protected array formatRules(array|string $rules)

Format validation rules.

Parameters

array|string $rules

Return Value

array

at line 1198
protected array|Closure mergeRules(string|array|Closure $input, string|array $original)

No description

Parameters

string|array|Closure $input
string|array $original

Return Value

array|Closure

at line 1221
protected void removeRule(string $rule)

Remove a specific rule by keyword.

Parameters

string $rule

Return Value

void

at line 1244
protected array sanitizeInput(array $input, string $column)

Sanitize input data.

Parameters

array $input
string $column

Return Value

array

at line 1259
protected string formatAttributes()

Format the field attributes.

Return Value

string

at line 1275
protected mixed getElementClassString()

Get element class string.

Return Value

mixed

at line 1298
protected string|array getElementClassSelector()

Get element class selector.

Return Value

string|array

at line 1322
protected string getGroupClass(bool $default = false)

Get element class.

Parameters

bool $default

Return Value

string

at line 1334
Field setGroupClass(string|array $class)

Set form group class.

Parameters

string|array $class

Return Value

Field

at line 1353
protected Field addVariables(array $variables = [])

Add variables to field view.

Parameters

array $variables

Return Value

Field

at line 1368
protected bool shouldRender()

If this field should render.

Return Value

bool