Validation Not Working On Scenario

Hi all, i have an issue where a custom validation rule worked before i set a scenario




array('customer_ID', 'justone'),



Where just one is a function that check that the user has chosen a customer from the dropdown or a checkbox to select all customers, however when i add a scenario




array('customer_ID', 'justone', 'on' => 'datarange'),



it doesn’t validate, and i now need the scenarios for different reports

i have set the scenario in the controller , any ideas ?

So, you mean to say you have set a scenario in your controller and your this validation rule is not triggered.Is it right ?

Could you please share your controller action call also.

Since, your defining a scenario might be wrong else it should not create any issue here.

Yeah sure





 public function actionIndex() {


        $this->layout = 'column1';

        $this->pageTitle = "Create report for date range";

       

        $model = new Reports;

         $model->setScenario('daterange');


       $this->performAjaxValidation($model);

        if (isset($_POST['Reports'])) {

            //create criteria and send to pdf

            $model->attributes = $_POST['Reports'];

            if ($model->validate()) {

                //begin criteria

                $criteria = new CDbCriteria;

                //dropdown first

                if (!empty($model->customer_ID)) {

                    

                    $criteria->compare('customer_ID', $model->customer_ID);

                    $criteria->addBetweenCondition('job_logged_date', $model->dateFrom, $model->dateTo);

                    $custmodel = Customers::model()->findbyPK($model->customer_ID);

                    $totalTime = $custmodel->total_time;

                    $title = "Date Range Job Report For :" . $custmodel->company . "   From : ".$model->dateFrom. " To : ". $model->dateTo."";

                    $subtitle = "Total time: " . $totalTime . "  Contracted Time : " . CHtml::encode($custmodel->aloc_time) . "";

                    $this->createpdf($criteria, $model, $title, $subtitle , $custmodel );

                } 

                else  {

                    //all customers checkbox

                    $criteria->addBetweenCondition('job_logged_date', $model->dateFrom, $model->dateTo);

                    $custmodel = Customers::model()->findAll();

                    $title = "Date Range Job Report For : All customers in date range ";

                    $subtitle = "";

                    $this->createpdf($criteria, $model, $title, $subtitle, $custmodel);

                }

            }

        }


        $this->render('index', array(

            'model' => $model,

        ));

    }



That is the whole action , and yeah the validation isnt trigered, its almost like its passing validation, but i am submitting a form that has nothing selected . It seems weird to me because i have scenarios working in other parts of the app

Don’t know if this has any significance but it is a form model , nothing is saved to the database

Your scenario in the model is "datarange" but in the controller you call it "daterange"

LOL oh no , thanks mate …its been a long day

:)

Its ok, think my eyes are getting tired as i checked for typos before posting , it was just the scenario name , thanks all

Glad you got rid off from that issue ;) I think its time for some rest isn’t it :D