KoolReport's Forum

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

Compare table input during Insert/Update with query result (from another table) #3350

Open Marloes opened this topic on on Oct 12 - 2 comments

Marloes commented on Oct 12

Hi,

Can I ask something. Is there a possibility in the Dashboard Admin Resource Table to verify (by query) an entered/selected value if it matches with a value in another table during an Insert or Update statement? F.e. in the CustomValidator or so:

Number::create("value_id")
                ->label("Something")
                ->sortable(true)
                ->validators([

                    CustomValidator::create()->validationFunction(function($value){

                        /////////////////////////////////////////////
                        // something to compare with
                        $q = get the value if it matches another table value (select second_value from some_table where parent_id = $value)
                        /////////////////////////////////////////////

                        if($value == $q["second_value"]){
                            return false;
                        } else {
                            return true;
                        }

                    })->errorMessage("La-di-da-di")
                ]),

With kind regards, Marloes

Sebastian Morales commented on Oct 17

In the validation function can you try to use datasource with $value like this:

CustomValidator::create()->validationFunction(function($value){
    $list = AutoMaker::table(...)
                ->select(...)
                ->where(...)  // use $value here             
                ->run();

If there's any issue let us know.

Marloes commented on Oct 17

Thx Sebastian!

That will do!

With kind regards, Marloes

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
help needed
solved
suggestion

Dashboard