Document custom form validation via Callback rule in Forms guide#455
Document custom form validation via Callback rule in Forms guide#455Copilot wants to merge 13 commits into
Callback rule in Forms guide#455Conversation
Agent-Logs-Url: https://github.com/yiisoft/docs/sessions/bb024534-e526-4189-b401-4dca5f506d38 Co-authored-by: vjik <525501+vjik@users.noreply.github.com>
Agent-Logs-Url: https://github.com/yiisoft/docs/sessions/bb024534-e526-4189-b401-4dca5f506d38 Co-authored-by: vjik <525501+vjik@users.noreply.github.com>
Callback rule in Forms guide
|
@copilot merge it with main form example and use yaml field as in https://github.com/yiisoft/validator/blob/master/docs/guide/en/built-in-rules-callback.md |
Agent-Logs-Url: https://github.com/yiisoft/docs/sessions/a7576578-7d52-4689-96cb-73c66933180d Co-authored-by: vjik <525501+vjik@users.noreply.github.com>
Agent-Logs-Url: https://github.com/yiisoft/docs/sessions/a7576578-7d52-4689-96cb-73c66933180d Co-authored-by: vjik <525501+vjik@users.noreply.github.com>
Updated in |
| In the above example, the `Form` has a single string property `$message` which length should be at least | ||
| of two characters. There's also a custom label for the property. | ||
|
|
||
| ## Custom validation with callback rule |
There was a problem hiding this comment.
@copilot don't create new section. Add new field to form example in "Creating a form" section
There was a problem hiding this comment.
Done in 637fe1f: removed the separate section and moved the YAML Callback field into the existing “Creating a form” example. Screenshot: /tmp/forms-creating-form-merged.png.
Agent-Logs-Url: https://github.com/yiisoft/docs/sessions/7e4e20c0-6bab-48c2-b4d2-345a41e0479b Co-authored-by: vjik <525501+vjik@users.noreply.github.com>
Agent-Logs-Url: https://github.com/yiisoft/docs/sessions/7e4e20c0-6bab-48c2-b4d2-345a41e0479b Co-authored-by: vjik <525501+vjik@users.noreply.github.com>
Agent-Logs-Url: https://github.com/yiisoft/docs/sessions/ebdb8606-d3e1-4065-86d6-f8d6617d9f66 Co-authored-by: vjik <525501+vjik@users.noreply.github.com>
Agent-Logs-Url: https://github.com/yiisoft/docs/sessions/ebdb8606-d3e1-4065-86d6-f8d6617d9f66 Co-authored-by: vjik <525501+vjik@users.noreply.github.com>
Agent-Logs-Url: https://github.com/yiisoft/docs/sessions/ebdb8606-d3e1-4065-86d6-f8d6617d9f66 Co-authored-by: vjik <525501+vjik@users.noreply.github.com>
Agent-Logs-Url: https://github.com/yiisoft/docs/sessions/ebdb8606-d3e1-4065-86d6-f8d6617d9f66 Co-authored-by: vjik <525501+vjik@users.noreply.github.com>
Done in
Done in |
|
|
||
| <?= $htmlForm->open() ?> | ||
| <?= Field::text($form, 'message')->required() ?> | ||
| <?= Field::text($form, 'yaml')->required() ?> |
There was a problem hiding this comment.
Done in d98eadc: switched the yaml field example to use a textarea and updated related wording accordingly. Screenshot: /tmp/forms-with-yaml-textarea-updated.png.
| #[Length(min: 2)] | ||
| public string $message = ''; | ||
|
|
||
| #[Callback(method: 'validateYaml')] |
There was a problem hiding this comment.
Done in d767eff: added a Label attribute to the yaml field in the main form example. Screenshot: /tmp/forms-label-attribute-updated.png.
Agent-Logs-Url: https://github.com/yiisoft/docs/sessions/1e2cda1d-9b78-4fa3-a78d-75ec80b31b40 Co-authored-by: vjik <525501+vjik@users.noreply.github.com>
Agent-Logs-Url: https://github.com/yiisoft/docs/sessions/d70634bb-2962-4194-b976-6de0578f8669 Co-authored-by: vjik <525501+vjik@users.noreply.github.com>
Addressed in |
The Forms guide did not explain how to perform custom validation beyond built-in attribute rules. This PR adds explicit guidance for callback-based validation directly in
src/guide/start/forms.md.What was missing
Length, etc.) but not custom verification logic in form models.yamlfield consistently.What was added
#[Callback(method: ...)]on a form property.Yiisoft\Validator\Result.yaml+validateYaml()) aligned with the validator callback rule documentation.Labelattribute for the YAML field in the form model example.yamlfield consistently (form rendering and explanatory flow), so examples remain aligned with the updated form model.Field::textarea($form, 'yaml')for YAML input in follow-up snippets.Example from the added docs