More compoonents for forms, enable select forms to have a read only appearance

This commit is contained in:
Deon George 2024-07-24 09:09:49 +10:00
parent 83bdea458f
commit 3a12ec005e
3 changed files with 15 additions and 2 deletions

View File

@ -1,3 +1,3 @@
<x-leenooks::form.base {{ $attributes }}>
<input type="email" class="form-control {{ $classes ?? ''}}@error($name) is-invalid @enderror" id="{{ $id ?? $name }}" name="{{ $name }}" value="{{ old($name,$value ?? '') }}">
<input type="email" class="form-control {{ $classes ?? ''}}@error($name) is-invalid @enderror" id="{{ $id ?? $name }}" name="{{ $name }}" value="{{ old($name,$value ?? '') }}" @readonly(isset($readonly)) @required(isset($required))>
</x-leenooks::form.base>

View File

@ -1,3 +1,3 @@
<x-leenooks::form.base {{ $attributes }}>
<input type="password" class="form-control {{ $classes ?? ''}}@error($name) is-invalid @enderror" id="{{ $id ?? $name }}" name="{{ $name }}" value="{{ old($name,$value ?? '') }}">
<input type="password" class="form-control {{ $classes ?? ''}}@error($name) is-invalid @enderror" id="{{ $id ?? $name }}" name="{{ $name }}" value="{{ old($name,$value ?? '') }}" @readonly(isset($readonly)) @required(isset($required))>
</x-leenooks::form.base>

View File

@ -1,4 +1,5 @@
<x-leenooks::form.base {{ $attributes }}>
<input type="hidden" id="{{ $name }}_disabled" name="{{ $name }}" value="" disabled>
<select class="form-control @error($name) is-invalid @enderror" id="{{ $id }}" name="{{ $name }}">
@if(isset($addvalues) && $addvalues)
<option id="new"></option>
@ -27,6 +28,18 @@
@js(select2,autofocus)
<script type="text/javascript">
// Select doesnt support read only so we'll use disable and a new field
function {{$id}}_readonly(on) {
if (on) {
$('#{{ $name }}').prop('disabled',true);
$('#{{ $name }}_disabled').prop('disabled',false).val($('#{{ $name }}').val());
} else {
$('#{{ $name }}').prop('disabled',false);
$('#{{ $name }}_disabled').prop('disabled',true);
}
}
$(document).ready(function() {
$('#{{ $id }}').select2({
dropdownAutoWidth: true,