Field types

Field types

Reference list of predefined custom fields to use with Assely framework.

Checkboxes

Adds field with list of checkable inputs.

Field::checkboxes($slug, $arguments = []);
Example

Use items argument for defining checkbox inputs. It accepts an associative array, where array key is checkbox name (that will be saved to the database) and text value, which will be displayed along with checkbox.

Field::checkboxes('checkboxes', [
    'items' => [
        'rum' => 'Is the rum gone?',
        'parley' => 'Parley?',
    ]
]);

You can set initial checkboxes values with default argument. It should contains array, where array key is checkbox slug and value is checkbox status.

Field::checkboxes('questions', [
    'items' => [
        'rum' => 'Is the rum gone?',
        'parley' => 'Parley?',
    ],
    'default' => [
        'rum' => false,
        'parley' => true,
    ],
]);
Template usage

The checkboxes field stores its items values as array of keys and booleans.

@if(! $post->meta('questions.rum'))
    <p>Why is rum always gone?</p>
@endif

Code

Adds code editor.

Field::code($slug, $arguments = []);
Changing editor mode

By default editor is in html mode, but you can change that with mode argument. Supported modes are html, css, javascript and markdown.

Field::code('code', [
    'mode' => 'css'
]);

Colorpicker

Adds colorpicker input.

Field::colorpicker($slug, $arguments = []);

Datepicker

Adds datepicker input.

Field::datepicker($slug, $arguments = []);

Editor

Adds text editor.

Field::editor($slug, $arguments = []);

Hidden

Adds hidden input.

Field::hidden($slug, $arguments = []);

Media

Adds media file input. Uses WordPress Media Library.

Field::media($slug, $arguments = []);
Setting default values

In order to set default image for media field, you have to define all nesseccary properties in default argument.

Field::media('media', [
    'title' => ['Media field'],
    'default' => [
        'id' => 10,
        'type' => 'image',
        'url' => wp_get_attachment_url(10),
    ],
])

Password

Adds password input.

Field::password($slug, $arguments = []);

Radios

Adds multiple radio inputs.

Field::radios($slug, $arguments = []);
Setting items

Use items argument for defining radios. It accepts an key => value array.

Field::radios('radios', [
    'items' => [
        'radio-1' => 'First radio',
        'radio-2' => 'Second radio'
    ]
]);
Setting default values

You can set initial value with default argument. It should contains key of choosen radio.

Field::radios('radios', [
    'items' => [
        'radio-1' => 'First radio',
        'radio-2' => 'Second radio',
    ],
    'default' => 'radio-2',
]);

Readonly

Adds readonly field that don't allows for changing it's value.

Field::readonly($slug, $arguments = []);

Repeatable

Adds repeatable field that allows for creating infinite repeated groups of fields.

Field::repeatable($slug, $arguments = []);
Example

Simply call children method with array of fields as argument.

Field::repeatable('repeat')->children([
    Field::colorpicker('colorpicker', [
        'default' => '#009d76'
    ])
])

Of course, repeatable fields can be infinitely nested. Yey!

Field::repeatable('repeat')->children([
    Field::text('text'),

    Field::repeatable('infinitely')->children([
        Field::colorpicker('colorpicker')
    ])
])
Template usage

The repetable field stores its children values as array. Just loop through with @foreach directive.

<ul>
    @foreach($post->get('repeat') as $field)
        <li style="color: {{ $field['colorpicker'] }}">
            {{ $field['colorpicker'] }}
        </li>
    @endforeach
</ul>

... or with multiple loops, in case of nested repeatable fields.

@foreach($post->meta('repeat') as $group)
    <h2>{{ $group['text'] }}</h2>

    <ul>
        @foreach($group['infinitely'] as $field)
            <li>{{ $field['colorpicker'] }}</li>
        @endforeach
    </ul>
@endforeach

Text

Adds simple text input. Perfect to store short strings.

Field::text($slug, $arguments = [])
Example
Field::text('text', [
    'default' => 'Why is the rum gone?',
    'description' => 'Asking the important question here.'
])
Template usage
<h2>{{ $term->meta('text') }}</h2>

Textarea

Adds textarea input.

Field::textarea($slug, $arguments = []);

Timepicker

Adds timepicker input.

Field::timepicker($slug, $arguments = []);

Tinymce

Adds WorPress Tinymce editor.

Field::tinymce($slug, $arguments = []);

Toggle

Adds toggle switch input.

Field::toggle($slug, $arguments = []);