Translate-plugin: Apply source model validation rules when saving translations

Created on 20 Feb 2017  路  6Comments  路  Source: rainlab/translate-plugin

I currently have a requirement to make a translatable attribute required. For the default language this works fine, but the required rule on the translated attribute is not triggered.

public $translatable = ['description'];
public $rules = ['description' => 'required'];

Is there any way to make the description field and all of its translations required?

Abandoned Conceptual Enhancement

All 6 comments

Not within the basic validation rules afaik. You could do custom validation within your model's beforeSave or beforeValidate methods.

How would you approach this @LukeTowers ? I've recently come across this validation hick-up when entering slugs. Our clients kept putting special characters in the slug, as German has got quite a lot of them.

Can we raise this as an issue here or at the October Core repository, because I think it's basic functionality that should one day be added. :)

@CptMeatball Are you talking about supporting unicode slugs?

I'm talking about this specific case:

public $rules = [
    'slug' => ['required', 'regex:/^[a-z0-9\/\:_\-\*\[\]\+\?\|]*$/i'],
];

public $translatable = [
    ['slug', 'index' => true],
];

If the slug field passes validation for the default language, it no longer looks at the validation of any extra languages.

So this would pass validation:

$slug[EN]: this-is-a-web-page
$slug[DE]: dis is eine webpagin盲

I've yet to thoroughly test this, but for one of our clients this has caused some mayhem. :P

Hmm, that's a good point. I imagine that this plugin could apply the validation rules for the attributes of the original model when saving the other languages. Feel free to look into a solution and make it as a PR

Closing as it has been over a month since any activity on this occurred.

Was this page helpful?
0 / 5 - 0 ratings