hello all!
i have this form with 2 droplist/
i have JS code that disable the second filed if i chose the first option.
but when i submit the form he stiil check validation to the disable filed
i try to find a solution on web and it has not succees
my form and JS:
<!-- forme -->
<div class="row">
<?php echo $form->labelEx($model,'workerToRole'); ?>
<?php echo $form->DropDownList($model,'workerToRole',Role::model()->getRolesList(),array('id'=>'wrole')); ?>
<?php echo $form->error($model,'workerToRole'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'workerToProfessions'); ?>
<?php echo $form->DropDownList($model, 'workerToProfessions', Profession::model()->getProfessionList(), array('id'=>'wpro','multiple'=>'multiple', 'size'=>5, )); ?>
<?php echo $form->error($model,'workerToProfessions'); ?>
</div>
<!-- JS-->
<script type="text/javascript">
$(document).ready(function() {
$("#wrole").change(function() {
if($(this).val() === "1") {
$("#wpro").removeAttr("disabled", "disabled");
} else {
$("#wpro").attr("disabled", "disabled");
}
});
});
</script>
controller:
public function actionCreate()
{
$model=new Worker;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Worker']))
{
$model->attributes=$_POST['Worker'];
if($model->save())
{
foreach ($_POST['Worker']['workerToRole'] as $role_code)
{
$modelr=new workerToRole;
$modelr->worker_code = $model->worker_code;
$modelr->role_code = $role_code;
if (!$modelr->save()) print_r($modelr->errors);
}role_code ==1){// this not work!!!! <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />
foreach ($_POST['Worker']['workerToProfessions'] as $profession_code)
{
$modelp=new workerToProfession;
$modelp->worker_code = $model->worker_code;
$modelp->profession_code = $profession_code;
if (!$modelp->save()) print_r($modelp->errors);
}
}
$this->redirect(array('view','id'=>$model->worker_code));
}
}
$this->render('create',array(
'model'=>$model,
));
}
can u help me?