Fix placement of error message

This commit is contained in:
Marcus Moore 2023-11-14 15:55:15 -08:00
parent 34cd106357
commit 20ae9dea19
No known key found for this signature in database
2 changed files with 6 additions and 2 deletions

View file

@ -970,7 +970,11 @@
errorClass: 'help-block form-error',
errorElement: 'span',
errorPlacement: function(error, element) {
element.parents('.required').append(error);
$(element).hasClass('select2')
// If the element is a select2 then place the error above the input
? element.parents('.required').append(error)
// Otherwise place it after
: error.insertAfter(element);
},
highlight: function(inputElement) {
$(inputElement).parent().addClass('has-error');

View file

@ -4,7 +4,7 @@
{{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }}
<div class="col-md-7{{ ((isset($field_req)) || ((isset($required) && ($required =='true')))) ? ' required' : '' }}">
<select class="js-data-ajax" data-endpoint="models" data-placeholder="{{ trans('general.select_model') }}" name="{{ $fieldname }}" style="width: 100%" id="model_select_id" aria-label="{{ $fieldname }}"{!! (isset($field_req) ? ' required ' : '') !!}{{ (isset($multiple) && ($multiple=='true')) ? " multiple='multiple'" : '' }}>
<select class="select2 js-data-ajax" data-endpoint="models" data-placeholder="{{ trans('general.select_model') }}" name="{{ $fieldname }}" style="width: 100%" id="model_select_id" aria-label="{{ $fieldname }}"{!! (isset($field_req) ? ' required ' : '') !!}{{ (isset($multiple) && ($multiple=='true')) ? " multiple='multiple'" : '' }}>
@if ($model_id = old($fieldname, ($item->{$fieldname} ?? request($fieldname) ?? '')))
<option value="{{ $model_id }}" selected="selected">
{{ (\App\Models\AssetModel::find($model_id)) ? \App\Models\AssetModel::find($model_id)->name : '' }}