Skip to content

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

Merged
giuscris merged 7 commits into
2.xfrom
feature/array-field-types-support
Nov 15, 2025
Merged

Add the possibility to specify field-related options to array field items#780
giuscris merged 7 commits into
2.xfrom
feature/array-field-types-support

Conversation

@giuscris

@giuscris giuscris commented Nov 9, 2025

Copy link
Copy Markdown
Member

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 giuscris added this to the 2.2.0 milestone Nov 9, 2025
@giuscris
giuscris requested a review from Copilot November 9, 2025 01:15
@giuscris giuscris self-assigned this Nov 9, 2025
@giuscris giuscris added the enhancement New feature or request label Nov 9, 2025

This comment was marked as outdated.

This comment was marked as outdated.

@getformwork getformwork deleted a comment from Copilot AI Nov 14, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 24 out of 24 changed files in this pull request and generated 11 comments.


馃挕 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread panel/src/ts/components/form.ts
Comment thread panel/src/ts/components/form.ts Outdated
Comment thread panel/src/ts/components/inputs/editor-input.ts
Comment thread formwork/fields/array.php
Comment thread formwork/fields/array.php
Comment thread panel/src/ts/components/inputs/editor-input.ts
Comment thread panel/src/ts/components/form.ts
Comment thread formwork/src/Data/AbstractCollection.php
Comment thread panel/src/ts/components/inputs/array-input.ts
Comment thread panel/src/ts/components/inputs/array-input.ts
@giuscris
giuscris marked this pull request as ready for review November 15, 2025 15:53
@giuscris
giuscris merged commit f81e3ab into 2.x Nov 15, 2025
2 checks passed
@giuscris
giuscris deleted the feature/array-field-types-support branch November 15, 2025 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants