goldenscarab/modulus-service-field

An helper to create html forms easily

v1.1.4 2023-01-20 12:30 UTC

README

A helper to generate HTML form fields in Bootstrap very easily

Required

  • Composer
  • PHP >= 7.2
  • Laravel >= 5.8

Installation

Require this package with composer.

composer require goldenscarab/modulus-service-field

Laravel 5.8 uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.

List of available fields

Input

// Simple
{!! Field::input([
    'label'  => 'Total',
    'name'   => 'total',
    'value'  => 23.4,
]); !!}

// Avanced
{!! Field::input([
    'label'           => 'Total',
    'name'            => 'total',
    'value'           => 23.4,
    'prefix'          => '<i class="fa fa-money"></i>',
    'suffix'          => '€',
    'help'            => 'Taxes included',
    'indice'          => 1,
    'inline'          => true,
    'attributes'      => [
        'id'           => 'total-final',
        'type'         => 'text',
        'class'        => 'text-danger',
        'placeholder'  => '123,30',
        'onchange'     => "console.log('change')",
        'style'        => 'background-color: #c3c3c3;',
        'data-type'    => 'money',
        'disabled'     => true,
        'readonly'     => true,
        'required'     => true,
        'autocomplete' => true,
        'autofocus'    => true
    ],
    'popover'     => [
        'placement' => 'right',
        'title'     => 'Information',
        'content'   => "Lorem ipsum dolor sit amet consectetur adipisicing elit. Repellendus ab fugiat recusandae quam incidunt quasi, molestiae velit quidem qui eos in delectus quo temporibus nam magnam excepturi nisi. Ipsa, deserunt."
    ],
]) !!}

Select

// Simple
{!! Field::select([
	'label' => 'My select', 
	'name'  => 'my_select',
	'options' => [
        'source' => [
            1 => 'Item 1',
            2 => 'Item 2'
        ]
    ]
]) !!}

// Simple with groupes
{!! Field::select([
	'label'       => 'My select',
    'name'        => 'my_select',
    'value'       => 23,
    'options' => [
        'default'    => ['value' => '', 'label' => 'Choose...'],
        'source' => [
            'Groupe 1' => [
                23 => 'Item 23',
                24 => 'Item 24',
                25 => 'Item 25',
            ],
            'Groupe 2' => [
                26 => 'Item 26',
                27 => 'Item 27',
                28 => 'Item 28',
            ]
        ]
    ]
]) !!}

// Avanced with Callback
{!! Field::select([
    'label'       => 'Collection',
    'name'        => 'collection',
    'value'       => [2, 4],
    'class'       => 'select2',
    'size'        => 'sm',
    'prefix'      => '<i class="fa fa-list"></i>',
    'suffix'      => '<i class="fa fa-hand-paper-o"></i>',
    'indice'      => 34,
    'attributes'  => [
        'class' => 'select2',
        'multiple' => true,
        'required' => true
    ],
    'options' => [
        'source' => $collection,
        'default' => ['value' => '', 'label' => 'Choose...'],
        'value'  => ':id',
        'label'  => ['callback' => [
            'function' => 'strtoupper',
            'args'     => ['template' => [
                'format' => '%s - %s',
                'args'   => [':title', ':value']
            ]]
        ]],
    ]
]); !!}

// Avanced with Data
{!! Field::select([
    'label'       => 'City',
    'name'        => 'city_id',
    'value'       => 2,
    'placeholder' => "Choose...",
    'options' => [
        'source' => [
            'call'   => 'Modules\City\Http\Controllers\Api\CityController@index',
            'params' => ['perpage' => 999],
            'target' => 'data'
        ],
        'default' => ['value' => '', 'label' => 'Choose a city...'],
        'value'   => ':id',
        'label'   => ['template' => [
            'format' => '%s - %s',
            'args'   => [':city.cp', ':city.name']
        ]],
        'attributes' => [
            'data-cp' => ':city.cp',
            'data-city' => ':city.name',
        ]
    ]
]) !!}

Textarea

{!! Field::textarea([
	'label'   => 'Content',
    'name'    => 'content',
    'value'   => $item->content,
    'attributes' => [
        'class'   => 'text-editor',
        'rows'    => 15,
    ]
]) !!}

Checkbox

// Simple
{!! Field::checkbox([
	'label'   => 'My checkboxes',
    'name'    => 'my_field_name',
    'value'   => [2, 3],
    'inline'  => true,
    'options' => [
        'source' => [
            1 => 'Item 1',
            2 => 'Item 2',
            3 => 'Item 3'
        ]],
]) !!}

// Avanced
{!! Field::checkbox([
    'label'   => 'My checkboxes',
    'name'    => 'my_field_name',
    'value'   => ['value-2', 'value-3'],
    'inline'  => true,
    'options' => [
        'source' => $collection,
        'value'  => ':id',
        'label'  => ['callback' => [
            'function' => 'strtoupper',
            'args'     => ['template' => [
                'format' => '%s - %s',
                'args'   => [':title', ':value']
            ]]
        ]],
        'attributes' => [
            'data-one' => ':data.data1',
            'data-two' => ':data.data2',
            'class' => [
                'condition' => [
                    'value'      => ':id',
                    'operator'   => '==',
                    'comparator' => 2,
                    'true'       => 'my-class-id-2',
                ]
            ]
        ]
    ]
] !!}

Radio

// Simple
{!! Field::radio([
	'label'   => 'Choix',
    'name'    => 'my_field_name',
    'value'   => 2,
    'inline'  => true,
    'options' => [
        'source' => [
            1 => 'Item 1',
            2 => 'Item 2',
            3 => 'Item 3'
        ]],
]) !!}

// Avanced
{!! Field::radio([
    'label'     => 'Mon Champs',
    'name'      => 'mon-champs',
    'value'     => 'value-2',
    'options'   => [
        'source'  => $collection,
        'value'  => ':id',
        'label'  => ['callback' => [
            'function' => 'strtoupper',
            'args'     => ['template' => [
                'format' => '%s - %s',
                'args'   => [':title', ':value']
            ]]
        ]],
        'attributes' => [
            'data-one' => ':data.data1',
            'data-two' => ':data.data2',
            'class' => [
                'condition' => [
                    'value'      => ':id',
                    'operator'   => '==',
                    'comparator' => 2,
                    'true'       => 'my-class-id-2',
                ]
            ]
        ]
    ]
]) !!}

Range

{!! Field::range([
	'label' => 'Zoom',
    'name'  => 'zoom',
    'value' => 7,
    'attributes' => [
        'min'   => -10,
        'max'   => 10,
    ],
]) !!}

Toggle

{!! Field::toggle([
    'label' => 'Toggle',
    'name'  => 'toggle',
    'value' => 1,
    'attributes' => [
        'data-on'       => 'Actif',
        'data-off'      => 'Inactif',
        'data-onstyle'  => 'success',
        'data-offstyle' => 'danger',
        'data-toggle'   => 'toggle',
        'data-width'    => '75',
        'data-size'     => 'xs'
    ]
]) !!}

File

{!! Field::file([
	'label'       => 'Uploader',
    'name'        => 'csv',
    'prefix'      => 'Fichier',
    'attributes'  => ['placeholder' => 'No file selected']
]) !!}
<style>
    .custom-file-label::after {
        content: 'Parcourir...'
    }
</style>

Image

{!! Field::image([
	'label'       => 'Champs image',
    'name'        => 'my_field_image',
    'value'       => 'image.png',
    'suffix'      => '<i class="fa fa-file-image-o mr-2"></i> Choisir une image',
    'attributes'  => [
        'placeholder' => 'ex: /upload/folder/image.png',
        'required'    => true,
    ]
]) !!}

Has identique field with pdf, video

Code

{!! Field::code([
    'label'       => 'Contenu',
    'name'        => 'content',
    'value'       => 'function foo(items) {
var x = "All this is syntax highlighted";
return x;
}',
    'attributes'  => [
        'required'        => false,
        'style'           => 'min-height: 400px;',
        'data-language'  => 'javascript',
        'data-readonly'  => 'true',
        'data-beautiful' => 'true',
    ]
]) !!}

Click here for more examples

Security

If you discover any security related issues, please email contact@goldenscarab.fr instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.