Skip to content

Comments

🐞 Fixed disappearing numeric field element keys#6

Merged
yoan-myparcel merged 2 commits intomasterfrom
hotfix/arr-collapse-destroys-keys
Sep 26, 2025
Merged

🐞 Fixed disappearing numeric field element keys#6
yoan-myparcel merged 2 commits intomasterfrom
hotfix/arr-collapse-destroys-keys

Conversation

@yoan-myparcel
Copy link
Member

@yoan-myparcel yoan-myparcel commented Sep 26, 2025

This pull request refactors how form element values are collected and returned, ensuring that keys are consistently integers and simplifying the value extraction logic. It also updates error handling in validation and aligns related tests to the new data structure.

Form value extraction improvements:

  • Refactored getValues in FormElementCollection to use Arr::mapWithKeys, which directly maps element names to their values, simplifying the code and ensuring keys are not collapsed or transformed unexpectedly. (src/Form/FormElementCollection.php, src/Form/FormElementCollection.phpL49-L56)

Validation error handling:

  • Changed the validate method in Form to throw FormValidationException with formatted error messages rather than raw error arrays, making errors clearer and easier to consume. (src/Form/Form.php, src/Form/Form.phpL45-R45)

Test updates for new value structure:

  • Updated test data and assertions in FormTest to use integer keys for form element names, reflecting the changes to the value extraction logic. (tests/Form/FormTest.php, [1] [2]

$validator->getErrors(),
);
throw new FormValidationException("Form validation failed", $validator->getErrors());
throw new FormValidationException("Form validation failed", $errorMessages);

Choose a reason for hiding this comment

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

FormValidationException::render expects $this->errors to have a property and a message key, so passing $errorMessages here will cause an undefined index error. I think $errorMessages can be deleted

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

@yoan-myparcel yoan-myparcel merged commit b4b90c2 into master Sep 26, 2025
1 check passed
@yoan-myparcel yoan-myparcel deleted the hotfix/arr-collapse-destroys-keys branch September 26, 2025 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants