CRUD Forms

Once you have created a new Crud Config, you need to set up the Form so that you can update Models through the CMS.

Forms are built up using Sections and Fields. For information on Sections and how to add Fields to them, see Sections

New Cruds

Sections are tabbed pages 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;
}

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;
}

Extending Existing Cruds.

By default, addSections appends them to the Section list. When creating new Crud Forms for your app, you can simply change the order of your code that you add Sections in to change the order that they appear on the tabbed navigation. When extending existing Crud Forms (for example, adding to Enso's built-in User Crud), you can use additional functions to add relative to 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 been 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);