feat(17-01): repeater field type and the dependent dropdown save recheck

- cabana: type repeater with nested form.fields (text, textarea, number,
  checkbox, switch, dropdown, richeditor), prompt, minItems, maxItems,
  titleFrom; groups, style, nested repeaters and other types fail boot
- rows decoded before projection: only nested keys, coerced scalars,
  per-row required (field.index.nested), row bounds; ProjectWritableFields
  exempts repeater lists only, nestedValue unchanged
- nested richeditor values sanitized with notices under the row path
- dependent dropdowns rechecked on save, top level and per row; null when
  the sibling takes no choice, 422 form.dependent_invalid otherwise
- dependent-options accepts repeater.field; schema carries RepeaterForm
- backend lang repeater.max_items, repeater.min_items,
  form.dependent_invalid; TestCompanionsRepeaterSmoke; docs
This commit is contained in:
2026-10-12 15:24:01 +02:00
parent 71fa597830
commit 46835fd064
16 changed files with 961 additions and 43 deletions

View File

@@ -168,9 +168,15 @@ func ProjectWritableFields(cc *CompiledController, body map[string]any) map[stri
}
allowed[field.Name] = field.FillKey
}
// A repeater's value is a list of rows (D-07): only those fields are
// exempt from the nested-value refusal, and only for a list.
repeaters := repeaterNames(cc)
for key, val := range body {
fillKey, ok := allowed[key]
if !ok || nestedValue(val) {
if !ok {
continue
}
if nestedValue(val) && !(repeaters[key] && listValue(val)) {
continue
}
out[fillKey] = val
@@ -557,6 +563,7 @@ func (actionConflict) Error() string { return "cabana: action does not apply" }
// every permissioneditor field as an object (D-16).
func projectFullRecord(ctx context.Context, tx *gorm.DB, cc *CompiledController, model any) (RecordResult, error) {
data := projectRecord(cc, model)
hydrateRepeaterFields(cc, data)
meta, err := projectRelationFields(ctx, tx, cc, model, data)
if err != nil {
return RecordResult{}, err
@@ -612,6 +619,12 @@ func (s CRUDService) save(ctx context.Context, cc *CompiledController, id any, i
if err := checkRichEditorValues(cc, in.Body, op); err != nil {
return RecordResult{}, err
}
// D-07: repeater rows are decoded in place (only nested keys, coerced
// scalars, per-row required, row bounds) before the projection, which
// lets a repeater's list through.
if err := liftRepeaterValues(ctx, cc, in.Body, op, s.tr); err != nil {
return RecordResult{}, err
}
var (
result RecordResult
notices []pluginNotice
@@ -638,6 +651,12 @@ func (s CRUDService) save(ctx context.Context, cc *CompiledController, id any, i
}
// D-10: every richeditor value is sanitized before Fill sees it.
notices = append(decoded.notices, sanitizeRichEditors(cc, projected)...)
notices = append(notices, sanitizeRepeaterRichEditors(cc, projected)...)
// D-08: a dependent dropdown's value must be among the options for
// its sibling's value, top level and in every repeater row.
if err := checkDependentValues(ctx, cc, s.tr, target, projected, op); err != nil {
return err
}
// The Form hooks read what this save writes for plugin field types.
ctx = withFieldWrites(ctx, decoded.writes)
if err := lagoon.Fill(target, fillAllowed(cc, target, op), projected, false); err != nil {
@@ -1096,7 +1115,8 @@ func mergedRules(ctx context.Context, cc *CompiledController, model any, op stri
// Relation fields are not writable columns. required stays on the
// schema for the client, but it cannot be checked by Fill. A virtual
// field is checked against its submitted value.
if field.Required && (valueFormField(field) || cc.virtual[field.Name]) && contextAllows(cc, field.Name, op) {
// A repeater's required is checked on its rows (liftRepeaterValues).
if field.Required && field.Type != repeaterType && (valueFormField(field) || cc.virtual[field.Name]) && contextAllows(cc, field.Name, op) {
out[field.Name] = mergeRequired(out[field.Name])
}
}
@@ -1260,7 +1280,7 @@ func scalarFormField(typ string) bool {
// valueFormField reports whether a controller form field binds to its model
// column: a scalar built-in type or a plugin field type.
func valueFormField(field FormField) bool {
return scalarFormField(field.Type) || field.fieldType != nil
return scalarFormField(field.Type) || field.fieldType != nil || field.Type == repeaterType
}
func protectedFillKey(key string) bool {