Does Yii2 support to show or hide attribute based on other attribute value at page load?

Hi everyone,

At present, I’m using javascript to hide or show an attribute at page load based on attribute radio button value. For example:


$(document).ready(function() {

    displaySource();

});


$('input[name="Article[source]"]').change(function(){

    displaySource();

});


/*

 * Show or hide corresponding source element base on radio button

 */

function displaySource() {

    if ($('input[name="Article[source]"]:checked').val() == '1') {

        $('.field-article-fileurl').show();

        $('.field-article-file').hide();

    } else {

        $('.field-article-fileurl').hide();

        $('.field-article-file').show();

    }

}

I have researched but I couldn’t find any way to do it with Yii2. Does Yii2 support to handle it? (Ex: In Model or ActiveForm, ActiveField)

This functionality is not present in Yii2.

You can build this script with help of [color="#4169E1"]registerJs()[/color] function at server side - it will help you handle ActiveForm field names.

Thank you for your support!