dillingham / formation

Laravel search, sort, and filters
MIT License
0 stars 0 forks source link

add fields #11

Open dillingham opened 2 years ago

dillingham commented 2 years ago
Field::make('id')->on(['index', 'show'])
Field::make('user_id')->value(fn() => auth()->id()))

^ that's really a prop of value right?

Field::make('price')->using('jet-number')->rules(['required', 'numeric', 'min:5', 'max:255'])
Field::make('price')
    ->using('jet-number')
    ->rules(['required', 'numeric', 'min:5', 'max:255'])

conditional fields: jet-form knows to hide inputs on change

Field::make('has_title')->using('jet-checkbox'),

Field::make('title')->when('has_title', 'on'),

dependant fields: jet-form knows to clear inputs on change and re-request options

Field::make('make')
    ->using('jet-select')
    ->prop('options', function() {
        return Make::pluck('title', 'id');
    }),

Field::make('model')
    ->using('jet-select')
    ->parent('make')
    ->prop('options', function(Parent $parent) {
        return Make::findOrFail($parent['make'])->models()->pluck('title', 'id');
    }),

Field::make('model')
    ->using('jet-select')
    ->parent(['make', 'model'])
    ->prop('options', function(Parent $parent) {
        return Year::findOrFail($parent['make'])->models()->pluck('title', 'id');
    }),

maybe call it listen and give the entire form value

Field::make('model')
    ->using('jet-select')
    ->listen(['make', 'model'])
    ->prop('options', function(Form $form) {
        return Year::findOrFail($form->make)->models()->pluck('title', 'id');
    }),
public $validateUpdatePartially = true;

// adds 'sometimes'

aggregate fields

Field::make('product_count')->count('products'),
Field::make('product_price_total')->sum('products.price'),
Field::make('product_price_avg')->avg('products.price'),
Field::make('product_price_max')->max('products.price'),
Field::make('product_price_min')->min('products.price'),

aggregate functions automatically set `->on(['index', 'show');

or maybe $is_input = false to enforce incase ->on is called after


json key value pair

Field::make('settings')->json([
    Field::make('notify_of_new_project'),
    Field::make('notify_of_new_order'),
    Field::make('notify_of_new_user'),
]),
{
    "notify_of_new_project": true,
    "notify_of_new_order": true,
    "notify_of_new_user": true,
}

array of objects / many json

Field::make('settings')->many([
    Field::make('first_name'),
    Field::make('last_name'),
]),
[
    { 
        "first_name": "Brian", 
        "last_name": "Dillingham" 
    },
    { 
        "first_name": "Brian", 
        "last_name": "Dillingham" 
    },
]

nested object within array of objects

Field::make('settings')->many([
    Field::make('first_name'),
    Field::make('last_name'),
    Field::make('settings')->json([
        Field::make('notify_of_new_project'),
    ])
]),
[
    { 
        "first_name": "Brian", 
        "last_name": "Dillingham", 
        "settings": { 
            "notify_of_new_project": true 
        } 
    },
]

maybe clean to add a view method


Field::make('email')
    ->render('jet-input', [
        'type' => 'email'
    ]),

Field::make('bio')
    ->render('jet-textarea', [
        'rows' => '5'
    ])

which under the hood  could just be looping and `->prop($key, $value)`
dillingham commented 2 years ago


 Field::make('ID');

        Field::make('Title');

        Field::make('Code')->span('6');

        Field::make('Slug')->span('6');

        Field::make('Summary')->component('ui-textarea');

        Field::make('Description')->component('ui-textarea');

        Field::make('Brand', 'brand_id')
            ->component('ui-picker')
            ->formation(BrandFormation::class);

        Field::make('Product Line', 'product_line_id')
            ->component('ui-picker')
            ->formation(ProductLineFormation::class)
            ->props(['parent' => 'brand_id']);

        // change chain to parent
//            'items-display' => 'title',
//            'url' => route('admin.brand.index'),
//            'items-path' => 'brands',

//                    v-model="values.brand_id"
//                    name="brand_id"
//                    items-path="brands"
//                    :url="route('admin.brands.index')"
//                    item-display="title"
//        [
//            "sort": formation->sort,
//            "trash": method_exists(formation->model, 'bootSoftDeleted'),
//            "fields": formation->fieldsForRoute('index'),