Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add rules support for per translations #21

Open
wants to merge 3 commits into
base: 3.x
Choose a base branch
from

Conversation

ferdiunal
Copy link

@ferdiunal ferdiunal commented Sep 26, 2024

Hello everyone,

This development aims to ensure that the rules defined for each locale work properly. I have added a setLocaleByRules method to the code. This method reattaches the locale-specific rules, defined as a Closure type in the rules method, back to the component before performing form validation.

With this change, form validation for different locales can be handled dynamically.

Example of how to use it rules:

public static function form(Form $form): Form
{
    return $form
        ->schema([
            Forms\Components\TextInput::make('name')
                ->label(__('Category Name'))
                ->helperText(__('This is the name of the category.'))
                ->rules(fn (?Category $record) => [
                    'tr' => ['required', 'string', 'max:100', Rule::unique('tags', 'name->tr')->where('type', 'category')->ignore($record?->id, 'id')],
                    'en' => ['required', 'string', 'max:100', Rule::unique('tags', 'name->en')->where('type', 'category')->ignore($record?->id, 'id')],
                ])
        ]);
}

Thank you.

@ferdiunal ferdiunal closed this Sep 26, 2024
@ferdiunal
Copy link
Author

There is an error I noticed in the beforeFill method, I will work on it and open it again

@ferdiunal ferdiunal reopened this Sep 26, 2024
@ferdiunal
Copy link
Author

I was using the getComponents method in my previous commit, but I realised that Form components could not be accessed due to spiral components such as Fieldset, Grid. I realised that I could solve this with getFlatComponents and made the necessary development.

@atmonshi
Copy link

atmonshi commented Oct 8, 2024

hey, sorry just saw this now :)

I like the idea, we can discuss it more. I'd appreciate it if you open a PR to this fork
for more.

thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants