I have a form, I divide its inputs in two parts in two tabs like this :
<ul class="nav nav-pills nav-justified">
<li class="tab active"><a data-toggle="tab" href="#infos">General Infos</a></li>
<li class="tab"><a data-toggle="tab" href="#other">Others</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="infos">
{!! BootForm::open()->action( route('admin.user.create') )->put()->class('validModal')->id('createUserForm') !!}
{!! BootForm::text('Last Name', 'lastname')->placeholder('bkf') !!}
{!! BootForm::text('First Name', 'firstname')->placeholder('aek') !!}
{!! BootForm::text('Username', 'username')->placeholder('bkf.aek') !!}
{!! BootForm::email('Email', 'email')->placeholder('bkf@aek.dz') !!}
...
</div>
<div class="tab-pane" id="other">
{!! BootForm::select('Grade', 'grade_id')->options($grades)->select('') !!}
{!! BootForm::password('Password', 'password') !!}
{!! BootForm::password('Password confirmation', 'password_confirmation') !!}
...
</div>
</div>
When I submit the form with missed values I get errors only in the first tab, so how can I display them in the second tab when I click on tab ? I'm looking for something like this :
$("li.tab").click(function (){
errors = response.errors;
// Iterate through errors object.
$.each(errors, function(field, message) {
console.error(field+': '+message);
var formGroup = $('[name='+field+']', form).closest('.form-group');
formGroup.addClass('has-error').append('<p class="help-block">'+message+'</p>');
});
});
Any idea please ?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire