nova-polymorphic-field
nova-polymorphic-field copied to clipboard
rules('required') is ignored
When saving a PolymorphicField::make('Type')
with a Text::make('Client')->rules('required')
field, the rules('required')
is ignored...
Possibly the solution in the Nova Dependency Container could resolve this issue? https://github.com/epartment/nova-dependency-container/issues/15
The solution used by nova-dependency-container suggested by @jasonlav seems to work for me. I just create a custom HasPolymorphicFields trait and use it instead of the one used by the package.
UPDATE This solution DOESN'T works. Validation rules are correctly applied but the store fails because Nova try to store the polymorphic fields also in the resource that contains them.
trait HasPolymorphicFields
{
/**
* @param NovaRequest $request
* @return FieldCollection
*/
public function availableFields(NovaRequest $request)
{
$fields = $this->fields($request);
$availableFields = [];
foreach ($fields as $field) {
if ($field instanceof PolymorphicField) {
$availableFields[] = $field;
foreach ($field->meta['types'] as $type) {
if ($this->doesRouteRequireChildFields()) {
$availableFields = array_merge($availableFields, $type['fields']);
}
}
} else {
$availableFields[] = $field;
}
}
return new FieldCollection(array_values($this->filter($availableFields)));
}
/**
* @return bool
*/
protected function requestIsAssociateRequest() : bool
{
return ends_with(Route::currentRouteAction(), 'AssociatableController@index');
}
/**
* @return bool
*/
protected function doesRouteRequireChildFields() : bool
{
return ends_with(Route::currentRouteAction(), 'AssociatableController@index')
|| ends_with(Route::currentRouteAction(), 'ResourceStoreController@handle')
|| ends_with(Route::currentRouteAction(), 'ResourceUpdateController@handle');
}
}
+1
I created a PR to fix validation problems for Nova Dependency Container . https://github.com/epartment/nova-dependency-container/pull/37
Hope that helps.
+1
+1
What about this issue? It still exists.
+1 - Still an issue.