-
Description:As discussed in #4648 there is an issue when using Detailed steps to reproduce the issue on a fresh Nova installation:See: #4648 Select::make('Field Type')
->options([
'text' => 'Text',
'number' => 'Number',
])
->onlyOnForms()
->displayUsingLabels(),
Number::make('Number', 'field_value')
->help('Number test')
->onlyOnForms()
->dependsOn(
['field_type'],
function (Number $field, NovaRequest $request, FormData $formData) {
if ($formData->field_type == 'number') {
$field
->show()
->rules('required');
} else {
$field
->hide();
}
}
),
Text::make('Text', 'field_value')
->help('Text test')
->onlyOnForms()
->dependsOn(
['field_type'],
function (Text $field, NovaRequest $request, FormData $formData) {
if ($formData->field_type == 'text') {
$field
->show()
->rules('required');
} else {
$field
->hide();
}
}
), |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 2 replies
-
Please add reproducing code. |
Beta Was this translation helpful? Give feedback.
-
See above - hope that's good |
Beta Was this translation helpful? Give feedback.
-
CleanShot.2022-10-18.at.18.07.12.mp4Unable to reproduce the issue, please provide full reproducing repository based on fresh installation as suggested in the bug report template (or you can refer to nova-issues/issue-4936@5b9b119 for example) |
Beta Was this translation helpful? Give feedback.
-
I have the same issue. Code to reproduce:
I hope it's clear now. In this case the attribute for second Select field and Number field is the same and Nova has the problem with displaying it correctly and handling. Of course there should be possibility to have two or more fields with the same name and using both of them with dependsOn. |
Beta Was this translation helpful? Give feedback.
-
Explain what you mean here. |
Beta Was this translation helpful? Give feedback.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
-
Ok, I will show more complex example:
Behaviour after I chose "Add surcharge" option: Behaviour after I chose "Set shipment type" option: Basically fields dependent on action are displayed completely wrong. For "Add surcharge" option you can see both also last Select, where it should not be displayed, and for option "Set shipment type" no field is displayed. |
Beta Was this translation helpful? Give feedback.
-
What's the return type of Having multiple |
Beta Was this translation helpful? Give feedback.
What's the return type of
AuditSpecificationCustomRuleModel::ADD_SURCHARGE
and wouldn'tSelect::make('Surcharge', 'action_parameters->0')
andSelect::make('Shipment type', 'action_parameters->0')
set as singleSelect
and you handle everything underdependsOn
. That's how you do it.Having multiple
Select
with same attribute name will not be supported in Nova.