Commit a48756e6 authored by alissonalbuquerque's avatar alissonalbuquerque
Browse files

add melhorias em mensagens de erro

parent 2968ef74
...@@ -12,15 +12,15 @@ ...@@ -12,15 +12,15 @@
$('#{{ $btn_submit_id }}').click(function(e) { $('#{{ $btn_submit_id }}').click(function(e) {
e.preventDefault() e.preventDefault()
const values = $('#{{ $form_id }}').serializeArray() const form = $('#{{ $form_id }}').serializeArray()
$('.ajax-errors').removeClass('alert alert-danger') $('.ajax-errors').removeClass('alert alert-danger is-valid is-invalid')
$('.ajax-errors span').empty(); $('.ajax-errors span').empty();
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: "{{ $route }}", url: "{{ $route }}",
data: values data: form
}).done(function(data, status) { }).done(function(data, status) {
if(data.status == 200) { if(data.status == 200) {
...@@ -33,6 +33,15 @@ ...@@ -33,6 +33,15 @@
duration: 3000 duration: 3000
}).showToast(); }).showToast();
let form_keys = form.map((item) => {
return item.name
})
form_keys = cleanFormKeys(form_keys, [])
form_keys.forEach((key) => {
$('#{{ $form_id }} #'+key).addClass('is-valid')
})
$('#{{ $form_id }}').submit() $('#{{ $form_id }}').submit()
} else { } else {
...@@ -43,10 +52,20 @@ ...@@ -43,10 +52,20 @@
}, },
duration: 3000 duration: 3000
}).showToast(); }).showToast();
let keys = Object.keys(data.errors) let form_keys = form.map((item) => {
return item.name
})
form_keys = cleanFormKeys(form_keys, Object.keys(data.errors))
form_keys.forEach((key) => {
$('#{{ $form_id }} #'+key).addClass('is-valid')
})
let keys = Object.keys(data.errors)
keys.forEach((key) => { keys.forEach((key) => {
$('#{{ $form_id }} #'+key).addClass('is-invalid')
$('#'+key+'_'+'{{ $form_type }}'+'-error').addClass('alert alert-danger') $('#'+key+'_'+'{{ $form_type }}'+'-error').addClass('alert alert-danger')
$('#'+key+'_'+'{{ $form_type }}'+'-error span').text(data.errors[key].shift()) $('#'+key+'_'+'{{ $form_type }}'+'-error span').text(data.errors[key].shift())
}) })
...@@ -64,4 +83,17 @@ ...@@ -64,4 +83,17 @@
}) })
}) })
function cleanFormKeys(_form_keys, _errors_keys)
{
let errors_keys = _errors_keys
errors_keys.push('_token')
errors_keys.push('user_pad_id')
return (
_form_keys.filter((key) => {
return !errors_keys.includes(key)
})
)
}
</script> </script>
...@@ -35,12 +35,12 @@ ...@@ -35,12 +35,12 @@
<div class="mb-3 col-sm-2"> <div class="mb-3 col-sm-2">
<label class="form-label" for="cod_atividade">Cód. Atividade</label> <label class="form-label" for="cod_atividade">Cód. Atividade</label>
<input class="form-control @error('cod_atividade') is-invalid @enderror" type="text" name="cod_atividade" id="cod_atividade" readonly> <input class="form-control @error('cod_atividade') is-invalid @enderror ajax-errors" type="text" name="cod_atividade" id="cod_atividade" readonly>
</div> </div>
<div class="mb-3 col-sm-5"> <div class="mb-3 col-sm-5">
<label class="form-label" for="componente_curricular">Componente Curricular</label> <label class="form-label" for="componente_curricular">Componente Curricular</label>
<input class="form-control @error('componente_curricular') is-invalid @enderror" type="text" name="componente_curricular" id="componente_curricular" value="{{ old('componente_curricular') }}"> <input class="form-control @error('componente_curricular') is-invalid @enderror ajax-errors" type="text" name="componente_curricular" id="componente_curricular" value="{{ old('componente_curricular') }}">
@include('components.divs.errors', [ @include('components.divs.errors', [
'field' => 'componente_curricular_create', 'field' => 'componente_curricular_create',
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
<div class="mb-3 col-sm-5"> <div class="mb-3 col-sm-5">
<label class="form-label" for="curso">Curso</label> <label class="form-label" for="curso">Curso</label>
<input class="form-control @error('curso') is-invalid @enderror" type="text" name="curso" id="curso" value="{{ old('curso') }}"> <input class="form-control @error('curso') is-invalid @enderror ajax-errors" type="text" name="curso" id="curso" value="{{ old('curso') }}">
@include('components.divs.errors', [ @include('components.divs.errors', [
'field' => 'curso_create' 'field' => 'curso_create'
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
<div class="mb-3 col-sm-3"> <div class="mb-3 col-sm-3">
<label class="form-label" for="nivel">Nível</label> <label class="form-label" for="nivel">Nível</label>
<select class="form-select @error('nivel') is-invalid @enderror" name="nivel" id="nivel" value="{{ old('nivel') }}"> <select class="form-select @error('nivel') is-invalid @enderror ajax-errors" name="nivel" id="nivel" value="{{ old('nivel') }}">
<option value="0">Selecione um Nível</option> <option value="0">Selecione um Nível</option>
@foreach($niveis as $value => $nivel) @foreach($niveis as $value => $nivel)
@if( $value == old('nivel') ) @if( $value == old('nivel') )
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
<div class="mb-3 col-sm-3"> <div class="mb-3 col-sm-3">
<label class="form-label" for="modalidade">Modalidade</label> <label class="form-label" for="modalidade">Modalidade</label>
<select class="form-select @error('modalidade') is-invalid @enderror" name="modalidade" id="modalidade" value="{{ old('modalidade') }}"> <select class="form-select @error('modalidade') is-invalid @enderror ajax-errors" name="modalidade" id="modalidade" value="{{ old('modalidade') }}">
<option value="0">Selecione uma Modalidade</option> <option value="0">Selecione uma Modalidade</option>
@foreach($modalidades as $value => $modalidade) @foreach($modalidades as $value => $modalidade)
@if( $value == old('modalidade') ) @if( $value == old('modalidade') )
...@@ -94,7 +94,7 @@ ...@@ -94,7 +94,7 @@
<div class="mb-3 col-sm-3"> <div class="mb-3 col-sm-3">
<label class="form-label" for="ch_semanal">CH. Semanal</label> <label class="form-label" for="ch_semanal">CH. Semanal</label>
<input class="form-control @error('ch_semanal') is-invalid @enderror" type="number" name="ch_semanal" id="ch_semanal" value="{{ old('ch_semanal') }}"> <input class="form-control @error('ch_semanal') is-invalid @enderror ajax-errors" type="number" name="ch_semanal" id="ch_semanal" value="{{ old('ch_semanal') }}">
@include('components.divs.errors', [ @include('components.divs.errors', [
'field' => 'ch_semanal_create' 'field' => 'ch_semanal_create'
...@@ -103,7 +103,7 @@ ...@@ -103,7 +103,7 @@
<div class="mb-3 col-sm-3"> <div class="mb-3 col-sm-3">
<label class="form-label" for="ch_total">CH. Total</label> <label class="form-label" for="ch_total">CH. Total</label>
<input class="form-control @error('ch_total') is-invalid @enderror" type="number" name="ch_total" id="ch_total" value="{{ old('ch_total') }}"> <input class="form-control @error('ch_total') is-invalid @enderror ajax-errors" type="number" name="ch_total" id="ch_total" value="{{ old('ch_total') }}">
@include('components.divs.errors', [ @include('components.divs.errors', [
'field' => 'ch_total_create' 'field' => 'ch_total_create'
......
...@@ -11,12 +11,12 @@ ...@@ -11,12 +11,12 @@
<div class="mb-3 col-sm-2"> <div class="mb-3 col-sm-2">
<label class="form-label" for="cod_atividade">Cód. Atividade</label> <label class="form-label" for="cod_atividade">Cód. Atividade</label>
<input class="form-control @error('cod_atividade') is-invalid @enderror" type="text" name="cod_atividade" id="cod_atividade" value="{{$model->cod_atividade}}" readonly> <input class="form-control @error('cod_atividade') is-invalid @enderror ajax-errors" type="text" name="cod_atividade" id="cod_atividade" value="{{$model->cod_atividade}}" readonly>
</div> </div>
<div class="mb-3 col-sm-5"> <div class="mb-3 col-sm-5">
<label class="form-label" for="componente_curricular">Componente Curricular</label> <label class="form-label" for="componente_curricular">Componente Curricular</label>
<input class="form-control @error('componente_curricular') is-invalid @enderror" type="text" name="componente_curricular" id="componente_curricular" value="{{$model->componente_curricular}}"> <input class="form-control @error('componente_curricular') is-invalid @enderror ajax-errors" type="text" name="componente_curricular" id="componente_curricular" value="{{$model->componente_curricular}}">
@include('components.divs.errors', [ @include('components.divs.errors', [
'field' => 'componente_curricular_update', 'field' => 'componente_curricular_update',
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
<div class="mb-3 col-sm-5"> <div class="mb-3 col-sm-5">
<label class="form-label" for="curso">Curso</label> <label class="form-label" for="curso">Curso</label>
<input class="form-control @error('curso') is-invalid @enderror" type="text" name="curso" id="curso" value="{{$model->curso}}"> <input class="form-control @error('curso') is-invalid @enderror ajax-errors" type="text" name="curso" id="curso" value="{{$model->curso}}">
@include('components.divs.errors', [ @include('components.divs.errors', [
'field' => 'curso_update', 'field' => 'curso_update',
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
<div class="mb-3 col-sm-3"> <div class="mb-3 col-sm-3">
<label class="form-label" for="nivel">Nível</label> <label class="form-label" for="nivel">Nível</label>
<select class="form-select @error('nivel') is-invalid @enderror" name="nivel" id="nivel" value="{{ old('nivel') }}"> <select class="form-select @error('nivel') is-invalid @enderror ajax-errors" name="nivel" id="nivel" value="{{ old('nivel') }}">
<option value="0">Selecione um Nível</option> <option value="0">Selecione um Nível</option>
@foreach($niveis as $value => $nivel) @foreach($niveis as $value => $nivel)
@if( $value == $model->nivel ) @if( $value == $model->nivel )
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
<div class="mb-3 col-sm-3"> <div class="mb-3 col-sm-3">
<label class="form-label" for="modalidade">Modalidade</label> <label class="form-label" for="modalidade">Modalidade</label>
<select class="form-select @error('modalidade') is-invalid @enderror" name="modalidade" id="modalidade"> <select class="form-select @error('modalidade') is-invalid @enderror ajax-errors" name="modalidade" id="modalidade">
<option value="0">Selecione uma Modalidade</option> <option value="0">Selecione uma Modalidade</option>
@foreach($modalidades as $value => $modalidade) @foreach($modalidades as $value => $modalidade)
@if( $value == $model->modalidade ) @if( $value == $model->modalidade )
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
<div class="mb-3 col-sm-3"> <div class="mb-3 col-sm-3">
<label class="form-label" for="ch_semanal">CH. Semanal</label> <label class="form-label" for="ch_semanal">CH. Semanal</label>
<input class="form-control @error('ch_semanal') is-invalid @enderror" type="number" name="ch_semanal" id="ch_semanal" value="{{$model->ch_semanal}}"> <input class="form-control @error('ch_semanal') is-invalid @enderror ajax-errors" type="number" name="ch_semanal" id="ch_semanal" value="{{$model->ch_semanal}}">
@include('components.divs.errors', [ @include('components.divs.errors', [
'field' => 'ch_semanal_update', 'field' => 'ch_semanal_update',
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
<div class="mb-3 col-sm-3"> <div class="mb-3 col-sm-3">
<label class="form-label" for="ch_total">CH. Total</label> <label class="form-label" for="ch_total">CH. Total</label>
<input class="form-control @error('ch_total') is-invalid @enderror" type="number" name="ch_total" id="ch_total" value="{{$model->ch_total}}"> <input class="form-control @error('ch_total') is-invalid @enderror ajax-errors" type="number" name="ch_total" id="ch_total" value="{{$model->ch_total}}">
@include('components.divs.errors', [ @include('components.divs.errors', [
'field' => 'ch_total_update', 'field' => 'ch_total_update',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment