This repository was archived by the owner on Jun 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 300
Creating Fields
Felice Ostuni edited this page Apr 23, 2015
·
13 revisions
To use your custom field on DataForm/DataEdit you need to specify the class namespace, i.e.:
$form->add('hexcolor','Color','App\Yourname\Fields\Colorpicker');
This class:
- must extend \Zofe\Rapyd\DataForm\Field\Field
- this class must have at least a property "type" for example $type = 'colorpicker';
- in this class you should override build() method to fill $this->output based on field 'status' (field status is a property that dataform share with fields, it can be: "show,create,modify, hidden")
- you can override (if needed): getValue() and getNewValue() to fill $this->value and $this->new_value
by default $this->value is filled by the value stored in the db and $this->new_value will be the new value on save (is a little more complicated but you get the idea).
Most of time if field is "simple" (doesn't require transformations) you need only to override build(). Like this one: https://github.com/zofe/rapyd-laravel/blob/master/src/DataForm/Field/Redactor.php
If you don't know how to setup a custom Namespace in Laravel this is a mini how-to:
- make a \app\Yourname folder
- make a \app\Yourname\Field folder
in this last folder put your fields:
<?php namespace App\Yourname\Field;
use Illuminate\Support\Facades\Form;
use Zofe\Rapyd\Rapyd;
use Zofe\Rapyd\DataForm\Field\Field;
class Myfield extends Field {
....
- then you must regenerate autoload by
composer dump-autoload
php artisan dump-autoload
- then you should be able to use your own fields:
$form->add('customfield','Asdasd','App\Yourname\Field\Myfield');
obviously if you need to include js/css assets you can put it on a /public/yourname/ folder then referencing in your field using:
Rapyd::js('yourname/myfield.min.js');
Rapyd::css('yourname/myfield.css');
if you're on Laravel 4 use a different namespace: namespace Yourname\Field
and add a psr-0 declaration for your namespace
presentation
editing