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

gte and lte support #72

Open
Causeofhell opened this issue Nov 10, 2024 · 2 comments
Open

gte and lte support #72

Causeofhell opened this issue Nov 10, 2024 · 2 comments
Milestone

Comments

@Causeofhell
Copy link

Causeofhell commented Nov 10, 2024

i want to use gte and lte rules, but when passing a field gives an error how can i manage that?
right now i am using a custom rule like this one

                ->rules([
                    fn (Get $get): Closure => function (string $attribute, $value, Closure $fail) use ($get) {
                        $minAmount = $get('min_amount');
                        $maxAmount = $get('max_amount');

                        // Convierte los valores a numéricos si es necesario
                        $value = floatval($value);
                        $minAmount = floatval($minAmount);
                        $maxAmount = floatval($maxAmount);

                        // Verifica que applied_amount esté dentro del rango
                        if ($value <= $minAmount) {
                            $fail("The {$attribute} must be greater than or equal to the minimum amount.");
                        }
                        if ($value >= $maxAmount) {
                            $fail("The {$attribute} must be less than or equal to the maximum amount.");
                        }
                    },
                ])
@pelmered
Copy link
Owner

Thank you for the report. What exactly is not working with this code?

There are already rules for max and min values of the field. Why you can't use them?

@pelmered
Copy link
Owner

Ah, ok. I think I was able to reproduce this now.

It is when you do something like this:

MoneyInput::make('estimated_total')
    ->locale('sv_SE')->minValue(function (Get $get) {
        return $get('other_field');
}),

You get an error like: Typed property Filament\Forms\Components\Component::$container must not be accessed before initialization

I will see how this can be fixed.

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

No branches or pull requests

2 participants