how to unhidden field base on the field validation in yii2

96 views Asked by At

i have some field that set to hidden and i want to unhidden the field based on the other field validation. how can i do this using jquery??

here is my code:

<?php $form = ActiveForm::begin([
'id' => 'assign-form',
'enableAjaxValidation' => true,

]); ?>

<?= $form->field($volunteeringin, 'acId', [
    'template' => '{label} <div class="row"><div class="col-md-5">{input}{error}{hint}</div></div>',
])->dropDownList($model->getActivitySearch(),['prompt'=>'בחר פעילות לשיבוץ המתנדב'])->label('פעילויות לשיבוץ')?>

<?= $form->field($volunteeringin, 'passedTraining')->radioList([0=>'לא',1=>'כן'] ,['separator' => '</br>','class'=>'hidden','id'=>'demo'])->label('האם המתנדב עבר הכשרה?'); ?>


<div class="form-group">
    <?= Html::submitButton( 'שבץ מתנדב' ,['class' =>  'btn btn-success' ]) ?>
</div>

<?php ActiveForm::end(); ?>

i want to set the field "passedTraining" to unhidden base on the the above field validation. i try to use this function:

   $('#fieldID').on('afterValidateAttribute', function(event, attribute, messages) {
        if(messages.length == 0){
            $('#demo').removeClass('hidden');
        }
    });

thanks eli

1

There are 1 answers

1
XzAeRo On

I tested your code, and you have just a small error:

<?php $form = ActiveForm::begin([
    'id' => 'assign-form',
    'enableAjaxValidation' => true,
    'enableClientValidation' => true, // enable this!
]); ?>

Hope this helps!