safe validator on condition

I am trying to use this rule in my model, but it’s not working.




[['dhanwantri_bill_number'], 'safe', 'when' => function($model) {               

                return $model->bill_type =='d';                 

            }, 'whenClient' => "function (attribute, value) {

                return $('#opdtestbill-bill_type').val() == 'd';

            }"],



Am I doing anything wrong?

is there any other solution to achieve the same.

Thanks.