Hey mates, I’m kinda stuck now and I don’t know what to do.
I’m working mainly with the Advanced Template and I’m stuck with the ajax-validation for unique usernames.
/frontend/models/SignupForm
(…)
public function rules()
{
return [
['username', 'filter', 'filter' => 'trim'],
['username', 'required'],
['username', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This username has already been taken.'],
['username', 'string', 'min' => 2, 'max' => 255],
['email', 'filter', 'filter' => 'trim'],
['email', 'required'],
['email', 'email'],
['email', 'string', 'max' => 255],
['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This email address has already been taken.'],
['password', 'required'],
['password', 'string', 'min' => 6],
];
}
(…)
In my signup.php
<?php $form = ActiveForm::begin([
'id' => 'form-signup',
'fieldConfig' => [
'template' => "{label}{input}{error}",
'options' => [
'tag' => 'p'
],
'errorOptions' => [
'tag' => 'span',
'class' => 'error-msg',
],
],
'requiredCssClass' => 'required-wrap',
]);
echo $form->field($model, 'username', [
'enableAjaxValidation' => true
])->textInput(['autofocus' => false])
?>
The part of checking, if there is actually text is working. Leaving the field without text ends up in an error-message "cannot be empty" (…)
However, entering my username, which is taken, changes the class of the wrapper to this:
<div class="field-signupform-username required-wrap validating">
The call is correct and I can see the response in my inspector. The error-message is there as well, right where it should be, but it isn’t in my “error-msg” span. Actually, it is nowhere. As if the validation never ends correct?!
The YiiWebAsset(js) is also included, if that takes care of it
Update 1
The Response is looking correctly. It shows the error-msg, even in the correct wrap. It looks like this:
<p class="field-signupform-username required-wrap has-error">
<label class="control-label" for="signupform-username">Username</label>
<input type="text" id="signupform-username" class="form-control" name="SignupForm[username]" value="MyNick">
<span class="error-msg">This username has already been taken.</span>
</p>
But it isn’t applied to my current site. As mentioined, it has the “has-error” class, while the live-form still has “validating”.
Please help me
Thanks guys