nova-translatable icon indicating copy to clipboard operation
nova-translatable copied to clipboard

'required' validation rule only enforced on one locale

Open nathan-io opened this issue 4 years ago • 3 comments

  • Laravel 6.0.4
  • Laravel Nova 2.9.2
  • mrmonat/nova-translatable 2.0.2

Say we have a field like:

Translatable::make( __('Slug'),  'slug')->rules('required')->sortable()->help(__('help.tips.slug')),

In our application, we have two locales.

If I try to submit the form without entering a value for either locale, I get a validation error stating that the field is required.

However, if I enter a value for only one of the two locales, the submission goes through.

How can we require that all a value is present for all locales?

nathan-io avatar Dec 31 '19 00:12 nathan-io

Same problem, do you have a solution now?

I think there are just miss some required parameter in file: https://github.com/mrmonat/nova-translatable/blob/master/resources/js/components/FormField.vue

approached avatar Oct 23 '20 14:10 approached

Any solutions? This is still a problem

austyuzhaninov avatar Apr 29 '21 08:04 austyuzhaninov

I have encountered this issue also. To resolve, I have added custom validation rules where I can verify if fr and en (and so on...) are not empty or else fail the validation. My code is bellow, can be improve validation

Let's analyze it a bit:

  • Here $attribute is not very useful because the value is something like flexible_content.0.text
  • $value is type of array with fr and en as key with their respective values
  • if one of en or fr value are missing, send fail validation

As you see, you can add more locales validation but for me i just use 'fr' and 'en'

Hope It helps

hernaval avatar Oct 05 '21 20:10 hernaval