formwork
formwork copied to clipboard
Add the possibility to specify field-related options to array field items
This pull request introduces significant improvements to the handling of array fields in forms, both in backend PHP logic and frontend TypeScript/SCSS code. The changes enhance validation, dynamic field creation, and UI consistency for array-type form inputs, especially for associative arrays and complex item types.
Backend: Array Field Enhancements
- Added support for
allowEmptyValuesand improved validation logic in thearrayfield type, ensuring empty values are handled according to configuration. - Introduced the
itemsmethod for dynamically generating fields for each array item usingFieldFactory, and areturnmethod for structured output. - Improved dependency injection in the field definition by passing
FieldFactoryto the closure. - Added a
keyBymethod toAbstractCollectionto allow collections to be indexed by item key, supporting the new array field logic. - Updated the
formNamemethod inFieldto allow overriding the form field name via options.
Frontend: Form and Array Input Refactor
- Refactored the
Formclass to use a unifiedformInputsarray and an association-based input loader, supporting dynamic and complex input types (including array fields). [1] [2] - Added a
duplicateInputmethod to theFormclass for duplicating input nodes, supporting dynamic addition of array items. - Refactored
ArrayInputto work with fieldsets, cache item inputs, and handle associative arrays more robustly, including correct value extraction and event binding. [1] [2]
UI/UX and Styling Improvements
- Updated SCSS for
.form-input-arrayand its children to improve layout, spacing, and support for different item types (e.g., markdown, textarea), resulting in a more consistent and flexible UI. [1] [2] - Added a translation for a new "toggleMarkdown" editor action.
Backend: Array Field Enhancements
- Added
allowEmptyValuessupport, improved validation, and dynamic item field generation to thearrayfield type informwork/fields/array.php. [1] [2] - Added
keyBymethod toAbstractCollectionfor key-based indexing, used by array fields. - Allowed overriding of form field names in the
Fieldclass via theformNamemethod.
Frontend: Form and Array Input Refactor
- Refactored the
Formclass to use an association-based loader for all input types, supporting dynamic and complex fields, and added input duplication logic. [1] [2] [3] - Refactored
ArrayInputto support fieldsets, improved value extraction, and better handling of associative arrays. [1] [2]
UI/UX and Styling Improvements
- Improved
.form-input-arraySCSS for better layout and support for various item types. [1] [2] - Added "toggleMarkdown" translation for the editor.