mardi 30 octobre 2018

Yii2: Show field/checkbox after checkbox is selected

I have an ActiveForm in my _form view:

<?php $form = ActiveForm::begin(); ?> <?= $form->field($model, 'isInternal')->checkbox() ?> <?php ActiveForm::end(); ?>

('isInternal' is a boolean)

If the checkbox is selected I want to show another checkbox:

$form->field($model, 'activateReminder')->checkbox();

Is there a possibility? Maybe with JavaScript like this?

 <?= $form->field($model, 'isInternal')->checkbox(['onclick' =>
 'showInternDetails()']) ?> 

<script>
 function showInternDetails() {
 $model->isInternal = 1;
 } 
</script>

<?php 
if($model->isInternal == true)
{
$form->field($model, 'activateReminder')->checkbox();
}
?>




Aucun commentaire:

Enregistrer un commentaire