Server-side validation for different min-max cell dependent. Possible?

Server-side validation for different min-max cell dependent. Possible?

mgagnemgagne Posts: 3Questions: 2Answers: 0

I am trying to do server-side validation in place of the client-side validation with the editor plugin but not sure if it is possible from what I am trying to do..

Essentially I have a recipe table with different ingredients. Each row is an ingredient with it's own unique min and max values. I would like to use the server-side validator but I haven't found any examples of how to apply a specific range to individual cells.

Ex: Ingredient Amount
Flour 80 - 88.23
Sugar 10 - 12.2

Use server-side validation to apply min-max per cell

Is this possible or should I just continue with client-side validation?

Answers

  • mgagnemgagne Posts: 3Questions: 2Answers: 0

    SOLUTION

    ->validator( function ($editor, $action, $data) {
            if ( $action == Editor::ACTION_EDIT ) {
                foreach ($data['data'] as $key => $values) {
                    $minmax = (float) $values['Quantity'];
                    $lowrange = (float) $values['AssignedLowRange'];
                    $highrange = (float) $values['AssignedHighRange'];
    
    
                        // If not within range, then report an error
                        if ( $minmax < $lowrange || $minmax > $highrange ) {
                            return 'Value must be between'. $lowrange . ' and '. $highrange;
                        }
                    }
                }
    
        } )
    
This discussion has been closed.