Hiding ActiveForm Fields when isNewRecord

I’ve currently implemented the following hack to remove fields from the form if you are creating a new record:


$render = null;


    $render = function($val){};



    <?= $form->field($model, 'description')->textInput(['maxlength' => 255])->render($render) ?>

Does anyone know of an actual built-in way to do this within the ActiveForm/Field codebase?

create class CustomActiveField extends yii\widgets\ActiveField and override method render

public function render($content = null)



return ‘’;}



Use it in ActiveForm:

$form = ActiveForm::begin([‘fieldClass’ => 'CustomActiveField ']);