Repeater Form Widget


Public Properties

public array $form

form field configuration

public array $groups

groups configuration

public string $prompt

prompt text for adding new items

public bool $showReorder

showReorder allows the user to reorder the items

public bool $showDuplicate

showDuplicate allow the user to duplicate an item

public string $titleFrom

titleFrom field name to use for the title of collapsed items

public string $groupKeyFrom

groupKeyFrom attribute stored along with the saved data

public int $minItems

minItems required. Pre-displays those items when not using groups

public int $maxItems

maxItems permitted

public string $displayMode

displayMode constant

public bool $itemsExpanded

itemsExpanded will expand the repeater item by default, otherwise they will be collapsed and only select one at a time when clicking the header.

public bool $useTabs

useTabs for the form fields.

public string $externalToolbarAppState

Defines a mount point for the editor toolbar. Must include a module name that exports the Vue application and a state element name. Format: stateElementName Only works in Vue applications and form document layouts.

Show inherited public properties

Inherited Public Properties

Protected Properties

protected $defaultAlias

defaultAlias to identify this widget.

protected array $indexMeta

indexMeta data associated to each field, organised by index

protected array $formWidgets

formWidgets collection

protected static bool $onAddItemCalled

onAddItemCalled sets the create context for default values

protected bool $useGroups

protected bool $useRelation

protected array $relatedRecords

relatedRecords when using a relation

protected array $groupDefinitions

protected boolean $isLoaded

isLoaded is true when the request is made via postback

protected array $modelsToSave

modelsToSave are models that require saving

Show inherited protected properties

Inherited Protected Properties

Public Methods

public getGroupCodeFromIndex()

public getGroupCodeFromIndex($index $index): string 

getGroupCodeFromIndex returns a field group code from its index

public getGroupItemConfig()

public getGroupItemConfig($groupCode, $name = null, $default = null): void

getGroupItemConfig returns the group config from its unique code

public getSaveValue()

public getSaveValue($value): void

getSaveValue processes the postback value for this widget. If the value is omitted from postback data, the form widget will be skipped.

public init()

public init(): void

init the widget, called by the constructor and free from its parameters.

public nearestModelAttribute()

public nearestModelAttribute($attribute): void

public onAddItem()

public onAddItem(): void

onAddItem handler

public onDuplicateItem()

public onDuplicateItem(): void

public onRefresh()

public onRefresh(): void

public onRemoveItem()

public onRemoveItem(): void

public prepareVars()

public prepareVars(): void

prepareVars for display

public render()

public render(): void

render the widget's primary contents.

public resetFormValue()

public resetFormValue(): void

resetFormValue from the form field

public resolveModelAttribute()

public resolveModelAttribute(string $attribute): array 

Returns the final model and attribute name of a nested HTML array attribute. Eg: [$model, $attribute] = $this->resolveModelAttribute($this->valueFrom);

Show inherited public methods

Inherited Public Methods

Protected Methods

protected createRelationAtIndex()

protected createRelationAtIndex($index, $groupCode = null): void

createRelationAtIndex prepares an empty model and adds it to the index

protected deferPurgedSaveAttributes()

protected deferPurgedSaveAttributes(
    October\Rain\Database\Model $model,
    array $attributesToPurge
): void 

deferPurgedSaveAttributes removes an array of attributes from the model. If the model implements the Purgeable trait, this is preferred over the internal logic.

protected deleteRelationAtIndex()

protected deleteRelationAtIndex($index): void

protected duplicateRelationAtIndex()

protected duplicateRelationAtIndex($fromIndex, $index, $groupCode = null): void

protected getDisplayMode()

protected getDisplayMode(): string 

getDisplayMode for the repeater

protected getGroupCodeFromJson()

protected getGroupCodeFromJson($value): void

protected getGroupCodeFromRelation()

protected getGroupCodeFromRelation($model): void

protected getGroupFormFieldConfig()

protected getGroupFormFieldConfig(string $code): array|null 

getGroupFormFieldConfig returns the form field configuration for a group, identified by code

protected getLoadValueFromRelation()

protected getLoadValueFromRelation(): void

protected getLoadedValueFromPost()

protected getLoadedValueFromPost(): void

getLoadedValueFromPost returns the loaded value from postback with indexes intact

protected getModelFromIndex()

protected getModelFromIndex($index): void

getModelFromIndex returns the model at a given index

protected getNextIndex()

protected getNextIndex(): int 

getNextIndex determines the next available index number for assigning to a new repeater item

protected getRelationModel()

protected getRelationModel(): Relation 

Returns the model of a relation type, supports nesting via HTML array.

protected getRelationObject()

protected getRelationObject(): Relation 

Returns the value as a relation object from the model, supports nesting via HTML array.

protected getRelationQuery()

protected getRelationQuery(): void

protected getRelationType()

protected getRelationType(): string 

getRelationType returns the value as a relation type from the model, supports nesting via HTML array.

protected getValueFromIndex()

protected getValueFromIndex($index): void

getValueFromIndex returns the data at a given index

protected isRelationTypeSingular()

protected isRelationTypeSingular(): bool 

isRelationTypeSingular checks if the related model is singular.

protected loadAssets()

protected loadAssets(): void

loadAssets adds widget specific asset files. Use $this->addJs() and $this->addCss() to register new assets to include on the page.

protected makeItemFormWidget()

protected makeItemFormWidget(
    int $index = 0,
    string $groupCode = null,
    int $fromIndex = null
): Backend\Widgets\Form 

makeItemFormWidget creates a form widget based on a field index and optional group code

protected moveTabbedFormFields()

protected moveTabbedFormFields($widget, $fromTab, $toTab): void

moveTabbedFormFields from one tab to another

protected performSaveOnModel()

protected performSaveOnModel($model, $data, $options = null): void

performSaveOnModel saves complex data against a model inside a database transaction.

protected prepareModelsToSave()

protected prepareModelsToSave(
    October\Rain\Database\Model $model,
    array $saveData
): array 

prepareModelsToSave takes a model and fills it with data from a multidimensional array. If an attribute is found to be a relationship, that relationship is also filled.

$modelsToSave = $this->prepareModelsToSave($model, [...]);

foreach ($modelsToSave as $modelToSave) {

protected processGroupMode()

protected processGroupMode(): void

processGroupMode processes features related to group mode

protected processItems()

protected processItems(): void

processItems processes data and applies it to the form widgets

protected processLegacyConfig()

protected processLegacyConfig(): void

processLegacyConfig converts deprecated options to latest

protected processLoadedState()

protected processLoadedState(): void

processLoadedState is special logic that occurs during a postback, the form field value is set directly from the postback data, this occurs during initialization so that nested form widgets can be bound to the controller.

protected processRelationMode()

protected processRelationMode(): void

protected processSaveForJson()

protected processSaveForJson($value): void

protected processSaveForRelation()

protected processSaveForRelation($value): void

protected processSaveValue()

protected processSaveValue(array $value): array|null 

processSaveValue splices in some meta data (group and index values) to the dataset

protected processSortOrderForSortable()

protected processSortOrderForSortable($model, $sortOrder): void 

protected setGroupCodeOnJson()

protected setGroupCodeOnJson(&$value, $groupCode): void

protected setGroupCodeOnRelation()

protected setGroupCodeOnRelation($model, $groupCode): void

protected setModelAttributes()

protected setModelAttributes(
    October\Rain\Database\Model $model,
    array $saveData,
    $attrName = ''
): void 

setModelAttributes sets a data collection to a model attributes, relations are also set.

Show inherited protected methods

Inherited Protected Methods