F
Filament12mo ago
Yasser

Disable Validation for other locales

Hello everyone, We have been looking for a while now.... Context - Several Resources, Translatable (Using Filament plugins, json columns and Spatie translatable) - Our other locales are 'optional' Issue The first time a field is filled (edit record), the validation triggers on the forms for the other locales. Question Is there a way to ignore any validation on the forms of the 'non' active locale. Or , to somehow (before validation) Fill the other forms's data with the default locale ones if they are empty ? Extra During my debugging I also found a qwerk in:
// This trait ->
Filament\Resources\Pages\EditRecord\Concerns\Translatable

// This Method ->
public function save(bool $shouldRedirect = true):void
{
// ... Code
// $this->activeLocale tends to return null if using the default locale
$originalActiveLocale = $this->activeLocale;
// ... Code
// If my active locale = 'en' it's still included
$otherTranslatableLocales = Arr::except($this->getTranslatableLocales(), $originalActiveLocale);
// Replacing this line with the equivalent?! does get me what's expected
$otherTranslatableLocales = array_filter(fn($locale)=>$locale!==$originalActiveLocale, $otherTranslatableLocales);
}
// This trait ->
Filament\Resources\Pages\EditRecord\Concerns\Translatable

// This Method ->
public function save(bool $shouldRedirect = true):void
{
// ... Code
// $this->activeLocale tends to return null if using the default locale
$originalActiveLocale = $this->activeLocale;
// ... Code
// If my active locale = 'en' it's still included
$otherTranslatableLocales = Arr::except($this->getTranslatableLocales(), $originalActiveLocale);
// Replacing this line with the equivalent?! does get me what's expected
$otherTranslatableLocales = array_filter(fn($locale)=>$locale!==$originalActiveLocale, $otherTranslatableLocales);
}
1 Reply
Yasser
YasserOP12mo ago
Solved by setting all empty data to the english data for every Locale in the beforeValidate hook, just seems a nuke for this tough (wish I could ignore validation on specific forms)
Want results from more Discord servers?
Add your server