Answer the question
In order to leave comments, you need to log in
How to properly clear inputs in ActiveForm in Yii2?
Hello!
There is a standard form:
<?php $form = ActiveForm::begin([
'id' => 'login-form',
'options' => ['class' => 'form-horizontal'],
'fieldConfig' => [
'template' => "{label}\n<div class=\"col-lg-3\">{input}</div>\n<div class=\"col-lg-8\">{error}</div>",
'labelOptions' => ['class' => 'col-lg-1 control-label'],
],
]);
?>
<?= $form->field($model, 'login') ?>
<?= $form->field($model, 'password') ?>
<?= $form->field($model, 'name') ?>
<div class='form-group'>
<div class='col-lg-offset-1 col-lg-11'>
<?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
<div class="form-group field-editform-login required">
<label class="control-label col-lg-3" for="editform-login">Логин</label>
<div class="col-lg-3"><input type="text" id="editform-login" class="form-control" name="EditForm[login]"></div>
<div class="col-lg-8"><p class="help-block help-block-error"></p></div>
</div>
<div class="form-group field-editform-login required has-error">
<label class="control-label col-lg-3" for="editform-login">Логин</label>
<div class="col-lg-3"><input type="text" id="editform-login" class="form-control" name="EditForm[login]"></div>
<div class="col-lg-8"><p class="help-block help-block-error">Такой логин уже есть в БД.</p></div>
</div>
$('form#edit-form input[type="text"]').each(function() {
$(this).removeAttr('value');
});
$('form#edit-form div.form-group').each(function() {
$(this).removeClass('has-error');
});
$('form#edit-form p.help-block').each(function() {
$(this).text('');
});
Answer the question
In order to leave comments, you need to log in
Return in the controller not the model that was loaded and validated, but new LoginForm().
So not?
window.onload = function(){
document.getElementById('field1').value = '';
document.getElementById('field2').value = '';
document.getElementById('field3').value = '';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question