CRUD Forms

CRUD Forms are built using the create and edit methods in your CRUD config. They are put together using using Sections and Fields. For information on Sections and how to add Fields to them, see Sections

New Cruds

Sections are the tabs on a Form. Each Section on a given Form must have a unique snake_case name. You can add one or more Sections to a Form in the create method of the Config.

public function create(Form $form)
{
    $form->addSection(
        Section::make('main')->addFields([
            ...
        ])
    );

    $form->addSections([
        Section::make('section_a'),
        Section::make('section_b'),
    ]);

    return $form;
}

By default the edit method returns the same as the create method but you can add edit-only Sections by extending and altering the edit method.

public function edit(Form $form)
{
    $form = $this->create($form);

    $form->addSection(
        Section::make('edit_only')->addFields([
            ...
        ])
    );

    return $form;
}

Managing Sections

By default, addSections appends them to the end of the Section list. When extending existing Crud Forms (for example, adding to Enso's built-in User Crud), you can use additional functions to add them in the correct order, before or after existing sections.

$form = parent::create($form);

$form->prependSection(Section::make('section_a'));

$form->addSectionBefore('main', Section::make('section_c'));

$form->addSectionAfter('main', Section::make('section_d'));

// This is included for deliberate specificity, but essentially does the same as `addSection`.
$form->appendSection(Section::make('section_a'));

You may want to change existing Sections. You can get Sections from a Form in two ways. Once you have found the Section you wish to alter, you can make changes directly to it. As it is an object, the variable references the same instance as the one in the Form's Section list. Subsequently, you don't need to replace the original Section on the Form with the one you have updated.

$sections = $form->getSections();
// ... returns a collection you can filter/search by

$section = $form->getSection('section_name');

You may want to remove entire Sections, You can remove them with removeSection.

$form->removeSection('section_name');

Finally, you may wish to transfer Fields from one Section to another. Perhaps you are looking to remove a Section, but retain a specific subset of the Fields. To achieve this, you can use extractSection. This will remove the Section with the provided name from the internal Sections list, and return it for you to pull Fields from:

$section = $form->extractSection('section_name');

$form->getSection('other_section')
    ->addField($section->getField('field_name'));

Autocomplete

You may want to turn off autocomplete for a whole form (as it's more reliable than doing it per-field, although still not fully reliable). To do so, you can add a setting to the form:

$form->allowAutocomplete(false);