0

i am trying to disable a field on update rules models but i am having error.

i try like:

array('date', 'constraint', 'readOnly'=>true, 'on'=>'update'),

but i am having this error:

"include(constraint.php): failed to open stream: No such file or directory"

I can disable from view using htmloptions but i need do it from model because on update i need to disable more than 5 fields.

how could i do this?

thx in advance

user468891
  • 321
  • 3
  • 11
  • That error is because the `Constraint` validator cannot be found. Instead of disabling the fields you could use plain text to display the values and hidden fields if the values are required for the next step. – topher Apr 03 '13 at 07:56
  • I need to disable them for avoid modifications but i need to let them visible. – user468891 Apr 03 '13 at 10:46
  • I think 'constraint' validation here may have come from reading http://www.yiiframework.com/forum/index.php/topic/4570-set-some-active-record-as-read-only/page__view__findpost__p__24179. That post goes on to say you need to create one. I haven't managed to get this to work. – russellfeeed Mar 20 '15 at 12:15

1 Answers1

5

You are declaring a rule with a validator that doesn't exist, so it's normal that you have an error:

array('date', 'constraint', 'readOnly'=>true, 'on'=>'update'),

This line is doing the following: apply the validator constraint on the date field on update scenario with param readOnly set to true.

The validator constraint doesn't exists has a built in functonnality in Yii so if you havn't created it then it doesn't exist!

Documentation:

Edit: In your form you could do something like:

<?php 
    echo $form->textField(
        $model,
        'email',
        array('readonly'=>($model->scenario == 'update')? true : false)
    );
?>

As you can see the readonly value will depend on the scenario.

darkheir
  • 8,844
  • 6
  • 45
  • 66