-
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filter data nested forms #68
base: master
Are you sure you want to change the base?
Conversation
DAGpro
commented
Sep 21, 2024
Q | A |
---|---|
Is bugfix? | ✔️ |
New feature? | ✔️ |
Breaks BC? | ❌ |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #68 +/- ##
============================================
Coverage 100.00% 100.00%
- Complexity 257 282 +25
============================================
Files 13 15 +2
Lines 598 717 +119
============================================
+ Hits 598 717 +119 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hydration of nested form models works for both one-to-one and one-to-many relations - #69. Also the tests are needed. What's the purpose of these changes exactly?
@arogachev The purpose of the changes, when working with nested form fields, is for the hydrator to receive the correct data structure.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Nested forms must use map loggic (see
FormHydrator::createMap()
). - Nested forms may be in properties with any variable scope (private/protected/public).
With dot-notation and array it will work without filtering.
|
I think, get a form is developer task. |
Map logic for nested forms awaits implementation yiisoft/hydrator#97 ? |
Yes, it's need to create nested mapping for hydrator. |
[
'firstForm' => Yiisoft\Hydrator\ObjectMap([
'map' => [
'secondForm' => Yiisoft\Hydrator\ObjectMap([
'map' =>
[
'value' =>
[
0 => 'firstForm',
1 => 'secondForm',
2 => 'value',
],
],
]),
],
]),
'value' => 'value',
]; [
'firstForm' => Yiisoft\Hydrator\ObjectMap([
'map' => [
'secondForm.value' => [
0 => 'firstForm',
1 => 'secondForm',
2 => 'value',
],
],
]),
'value' => 'value',
]; There is a question of resolving such cases. When specifying a Nested rule with a null argument on a parent form, ignore the property with the embedded form and the rules from that form? |
When |
Review? |
@@ -9,6 +9,13 @@ use Yiisoft\FormModel\FormModel; | |||
|
|||
/** @var FormModel $formModel */ | |||
$field = Field::text($formModel, 'login'); | |||
|
|||
/** Display fields nested forms */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** Display fields nested forms */ | |
/** Display nested form */ |
Does that display whole form?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whole?
nested form field or nested form 🤷♂️
@vjik would you please take a look at it? |
Do |
Are you interested in using widgets directly from "yiisoft/form" or via the "formModel/Field" helper? Filling out nested forms is allowed in the filterNestedForms method, error collection for nested forms is allowed in the validator package via the Nested rule class. When using nested forms directly with the output of errors there are no problems, when using dot-notation and an array, all errors of nested fields are output in the parent field. |
echo \Yiisoft\FormModel\Field::text($mainForm, 'value');
echo \Yiisoft\FormModel\Field::text($mainForm->firstNestedForm(), 'value');
echo \Yiisoft\FormModel\Field::number($mainForm->firstNestedForm()->secondForm(), 'value');
echo \Yiisoft\FormModel\Field::number($mainForm->firstNestedForm()->secondForm(), 'string'); <div>
<label for="mainform-value">Value</label>
<input type="text" id="mainform-value" name="MainForm[value]" value="v">
<div>Value must contain at least 3 characters.</div>
</div>
<div>
<label for="firstnestedform-value">Value</label>
<input type="text" id="firstnestedform-value" name="FirstNestedForm[value]" value="va">
<div>Value must contain at least 3 characters.</div>
</div>
<div>
<label for="secondnestedform-value">Value</label>
<input type="number" id="secondnestedform-value" name="SecondNestedForm[value]">
<div>
Value cannot be blank.
<br>
The allowed types for value are integer, float and string. null given.
</div>
</div>
<div>
<label for="secondnestedform-string">String</label>
<input type="number" id="secondnestedform-string" name="SecondNestedForm[string]" value>
<div>
String cannot be blank.
<br>
String must contain at least 4 characters.
</div>
</div> echo Text::widget()->inputData(new \Yiisoft\Form\PureField\InputData(
"MainForm[value]",
$mainForm->value,
validationErrors: $mainForm->firstNestedForm()->secondForm()->getValidationResult()->getErrorMessages(),
));
echo Text::widget()->inputData(new \Yiisoft\Form\PureField\InputData(
"FirstNestedForm[value]",
$mainForm->firstNestedForm()->value,
validationErrors: $mainForm->firstNestedForm()->secondForm()->getValidationResult()->getErrorMessages(),
));
echo Text::widget()->inputData(new \Yiisoft\Form\PureField\InputData(
"SecondNestedForm[value]",
$mainForm->firstNestedForm()->secondForm()->value,
validationErrors: $mainForm->firstNestedForm()->secondForm()->getValidationResult()->getErrorMessages(),
)); <div>
<input type="text" name="MainForm[value]" value="v">
<div>
Value cannot be blank.
<br>
The allowed types for value are integer, float and string. null given.
<br>
String cannot be blank.
<br>
String must contain at least 4 characters.
</div>
</div>
<div>
<input type="text" name="FirstNestedForm[value]" value="va">
<div>
Value cannot be blank.
<br>
The allowed types for value are integer, float and string. null given.
<br>
String cannot be blank.
<br>
String must contain at least 4 characters.
</div>
</div>
<div>
<input type="text" name="SecondNestedForm[value]">
<div>
Value cannot be blank.
<br>
The allowed types for value are integer, float and string. null given.
<br>
String cannot be blank.
<br>
String must contain at least 4 characters.
</div>
</div> |
This PR required more time for review. Give me more time, I detailed review as soon as possible. |