How to correctly clear the input's s 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(); ?>

There are all sorts of validators, after which can you see messages, for example, if the input login is invalid:
<div class="form-group field-editform-login required">
<label class="control-label col-lg-3" for="editform-login">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>

when you click login, there will be a reboot of the page and the login field is added to the error class has-error and the message "This username is already in DB.":
<div class="form-group field-editform-login required has-error">
<label class="control-label col-lg-3" for="editform-login">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">This username is already in DB.</p></div>
</div>


The problem is that this form I have a modal window and re-open it I want to clear all fields and remove the display of all errors.
At the moment jQuery methods, I have achieved the desired result, the opening of the modal window, I'm hanging commands:
$('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(");
 });

I removed all value from input type="text", remove the class has-error, and overwrite error message.
All is good, but after that there is a bug:
If you stand on the username field, do not enter anything and go to the next field, the error field is null or blank is triggered from all input's s, and before that error appeared only from input'a where I left the cursor.

Why is this happening and how to make a normal cleanup? Perhaps there is a less clumsy solution in the ActiveForm class?
July 8th 19 at 11:59
2 answers
July 8th 19 at 12:01
Return in the controller not the model that download and providerbase and new LoginForm().
it did not happen, because there is no page reload. - damian_Labadie commented on July 8th 19 at 12:04
but you wrote "restart page" - ephraim_Schumm commented on July 8th 19 at 12:07
: there was a situation, so your idea is partly helped, but there is also the situation when you need to reset the value of the fields without reloading. - damian_Labadie commented on July 8th 19 at 12:10
By the way, your problem Google easy. $form.reset().trigger('reset'); - ephraim_Schumm commented on July 8th 19 at 12:13
: $('form#edit-form').reset().trigger('reset'); this command does not reset the values I have. - damian_Labadie commented on July 8th 19 at 12:16
: where exactly should this command to register? ($form.reset().trigger('reset')) - damian_Labadie commented on July 8th 19 at 12:19
: In short, I understand how the reset works, but it does not suit me, need to understood why after reset the value at input error will be triggered on all fields at once. - damian_Labadie commented on July 8th 19 at 12:22
try to clear the field with value=undefined and not an empty string. - ephraim_Schumm commented on July 8th 19 at 12:25
: after the reset you do something else? For example, clear the field? In fact, you only need a reset and all he will do after his should go no instructions on cleaning, otherwise you lose default settings. - ephraim_Schumm commented on July 8th 19 at 12:28
: value undefined helped! thank you very much!!! - damian_Labadie commented on July 8th 19 at 12:31
July 8th 19 at 12:03
So not?
window.onload = function(){
document.getElementById('field1').value = ";
document.getElementById('field2').value = ";
document.getElementById('field3').value = ";
}
I have no problem with clearing fields. - damian_Labadie commented on July 8th 19 at 12:06

Find more questions by tags Yii