formwork icon indicating copy to clipboard operation
formwork copied to clipboard

Add the possibility to specify field-related options to array field items

Open giuscris opened this issue 2 months ago • 0 comments

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 allowEmptyValues and improved validation logic in the array field type, ensuring empty values are handled according to configuration.
  • Introduced the items method for dynamically generating fields for each array item using FieldFactory, and a return method for structured output.
  • Improved dependency injection in the field definition by passing FieldFactory to the closure.
  • Added a keyBy method to AbstractCollection to allow collections to be indexed by item key, supporting the new array field logic.
  • Updated the formName method in Field to allow overriding the form field name via options.

Frontend: Form and Array Input Refactor

  • Refactored the Form class to use a unified formInputs array and an association-based input loader, supporting dynamic and complex input types (including array fields). [1] [2]
  • Added a duplicateInput method to the Form class for duplicating input nodes, supporting dynamic addition of array items.
  • Refactored ArrayInput to 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-array and 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 allowEmptyValues support, improved validation, and dynamic item field generation to the array field type in formwork/fields/array.php. [1] [2]
  • Added keyBy method to AbstractCollection for key-based indexing, used by array fields.
  • Allowed overriding of form field names in the Field class via the formName method.

Frontend: Form and Array Input Refactor

  • Refactored the Form class to use an association-based loader for all input types, supporting dynamic and complex fields, and added input duplication logic. [1] [2] [3]
  • Refactored ArrayInput to support fieldsets, improved value extraction, and better handling of associative arrays. [1] [2]

UI/UX and Styling Improvements

  • Improved .form-input-array SCSS for better layout and support for various item types. [1] [2]
  • Added "toggleMarkdown" translation for the editor.

giuscris avatar Nov 09 '25 01:11 giuscris