Refactor form initialization to enable optional password updates#861
Merged
Refactor form initialization to enable optional password updates#861
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors panel form initialization to consistently seed field values (and validation state) across several controllers, while enhancing the password field type to support optional updates without overwriting existing values with empties.
Changes:
- Added
ignoreEmpty()andsetValue()field-type methods forpasswordfields to optionally preserve the previous value when an empty value is set. - Updated the password field view so the
requiredattribute is omitted whenignoreEmptyis enabled. - Simplified multiple panel controllers by removing
RequestMethod::GETguards and always initializing field values + validation state.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| panel/views/fields/password.php | Makes required conditional on ignoreEmpty for password inputs. |
| formwork/fields/password.php | Introduces ignoreEmpty and setValue hooks to preserve existing password values on empty input. |
| formwork/src/Panel/Controllers/UsersController.php | Always seeds user profile field values and pre-validates to initialize validation state. |
| formwork/src/Panel/Controllers/PluginsController.php | Always seeds plugin option field values and pre-validates to initialize validation state. |
| formwork/src/Panel/Controllers/PagesController.php | Always seeds page editor field values and pre-validates to initialize validation state. |
| formwork/src/Panel/Controllers/OptionsController.php | Always seeds system/site options values and pre-validates to initialize validation state. |
| formwork/src/Panel/Controllers/FilesController.php | Always seeds file metadata values and pre-validates to initialize validation state. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces enhancements to the handling of password fields and streamlines the initialization of field values across several controller methods. The most significant change is the addition of new methods to the password field type, allowing for more flexible handling of empty values. Additionally, redundant checks for HTTP request methods when setting initial field values have been removed from multiple controllers, simplifying the codebase and ensuring that field validation state is always initialized.
Password field enhancements:
ignoreEmptyandsetValuemethods to the password field type inpassword.php, allowing the field to retain its value if empty and theignoreEmptyoption is enabled. This helps prevent overwriting existing passwords with empty values during form submissions.requiredattribute only if the field is required and not set to ignore empty values, improving user experience and validation accuracy.Field initialization and validation simplification:
RequestMethod::GETwhen setting initial field values and pre-validating fields in theeditand options methods ofFilesController,PagesController,OptionsController,PluginsController, andUsersController. Now, field values are always initialized and validated, regardless of the request method, reducing code complexity and potential inconsistencies. [1] [2] [3] [4] [5] [6]Code cleanup:
RequestMethodfrom several controller files, as the related conditional logic has been eliminated. [1] [2] [3] [4] [5]