F
F
Fyodor Dostoyevsky2014-07-11 16:54:45
Yii
Fyodor Dostoyevsky, 2014-07-11 16:54:45

How to display only "label" and "error" for a form (ActiveField) in Yii2?

Hello. Does anyone know how to display only "label" and "error" for a form (ActiveField) in Yii2?
I'm using the Redactor extension , with it you can only display the input field itself, but I also want to display the title for the field and the validation error.
The *yii\imperavi\Widget::widget* widget itself displays only the input field, without a title and errors. I hope everything is clear.

<?php $form = ActiveForm::begin(); ?>
    <?php echo $form->errorSummary($model); ?>
    <?= $form->field($model, 'title')->textInput(['maxlength' => 255]) ?>

    <?php echo yii\imperavi\Widget::widget(
        [
            'model' => $model,
            'attribute' => 'text',
            'options' => [],
        ]
    );
    ?>
    <br />
    <div class="form-group">
        <?= Html::submitButton(
            $model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'),
            ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']
        ) ?>
    </div>
    <?php ActiveForm::end(); ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
papahoolio, 2014-07-11
@papahoolio

Yii1. What if you add it yourself?

<?= $form->labelEx($model, 'title') ?>
<?= $form->field($model, 'title')->textInput(['maxlength' => 255]) ?>
<?= $form->error($model,'title') ?>

Yii2. It is possible to try then a template of a field to torment
<? $form->field($model, 'title')->template = "{label}\n{hint}\n{error}"; ?>
<?=$form->field($model, 'title')?>
Alternatively, you can make your own class for the field inherited from ActiveField.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question