KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Resource - how to compare #3332

Open cyberweb opened this topic on on Sep 6 - 1 comments

cyberweb commented on Sep 6

How to use compare validators in resource ?

With dashboard it's works but not in resource

Please find my code :

            Number::create("min_duration")
                ->label($this->tr->trad('min_duration'))
                ->searchable(true)
                ->sortable(true)
                ->showOnIndex(false)
                ->showOnCreate(true)
                ->showOnUpdate(true)
                ->inputWidget(
                    TextBox::create("min_duration")
                )
                ->validators([
                    NumericValidator::create(),
                ]),
            Number::create("max_duration")
                ->label($this->tr->trad('max_duration'))
                ->searchable(true)
                ->sortable(true)
                ->showOnIndex(false)
                ->showOnCreate(true)
                ->showOnUpdate(true)
                ->inputWidget(
                    TextBox::create("max_duration")
                )
                ->validators([
                    NumericValidator::create(),
                    CompareValidator::create()
                        ->inputToValidate("min_duration")
                        ->inputToCompare("min_duration") // Compare with min_duration field
                        ->errorMessage("Max duration should be equal to min duration")
                        ->operator("=") // Compare for equality

Thanks

KoolReport commented on Sep 9

Please do this:

                    CompareValidator::create()
                        ->inputToCompare("min_duration_input") // Compare with min_duration field
                        ->errorMessage("Max duration should be equal to min duration")
                        ->operator("=") // Compare for equality

Let see if it works.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

None