Add error handling via tooltip
This commit is contained in:
		
							parent
							
								
									6cd896d7c9
								
							
						
					
					
						commit
						397ff52e35
					
				|  | @ -47,6 +47,7 @@ class Select extends Component | ||||||
|                         <option value="{{$option['id']}}">{{ $option['name'] }}</option> |                         <option value="{{$option['id']}}">{{ $option['name'] }}</option> | ||||||
|                         @endforeach |                         @endforeach | ||||||
|                     </select> |                     </select> | ||||||
|  |                     <x-ui::errors :for="$name" /> | ||||||
|                     @if($hint) |                     @if($hint) | ||||||
|                     <x-form::hint class="right-6">{{$hint}}</x-form::hint> |                     <x-form::hint class="right-6">{{$hint}}</x-form::hint> | ||||||
|                     @endif |                     @endif | ||||||
|  |  | ||||||
|  | @ -44,6 +44,7 @@ class Text extends Component | ||||||
|                         " |                         " | ||||||
|                         {{ $attributes }} |                         {{ $attributes }} | ||||||
|                     /> |                     /> | ||||||
|  |                     <x-ui::errors :for="$name" /> | ||||||
|                     @if($hint) |                     @if($hint) | ||||||
|                     <x-form::hint>{{$hint}}</x-form::hint> |                     <x-form::hint>{{$hint}}</x-form::hint> | ||||||
|                     @endif |                     @endif | ||||||
|  |  | ||||||
|  | @ -0,0 +1,33 @@ | ||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | namespace App\View\Ui; | ||||||
|  | 
 | ||||||
|  | use Illuminate\View\Component; | ||||||
|  | 
 | ||||||
|  | class Errors extends Component | ||||||
|  | { | ||||||
|  | 
 | ||||||
|  |     public function __construct( | ||||||
|  |         public string $for, | ||||||
|  |     ) { | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public function id(): string | ||||||
|  |     { | ||||||
|  |         return 'errors-' . str_replace('.', '--', $this->for); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public function render() | ||||||
|  |     { | ||||||
|  |         return <<<'HTML' | ||||||
|  |             @error($for) | ||||||
|  |             <div x-data="{error: ''}" x-init="window.setTimeout(() => document.querySelector('#{{$id()}}') ? document.querySelector('#{{$id()}}').remove() : null, 2000)" class="absolute bottom-[calc(100%+0.5rem)] right-0" id="{{$id}}"> | ||||||
|  |                 <div class="tippy-box" tabindex="-1" data-theme="danger" data-placement="top"> | ||||||
|  |                     <div class="tippy-content">{{$message}}</div> | ||||||
|  |                     <div class="tippy-arrow absolute right-0 mr-2"></div> | ||||||
|  |                 </div> | ||||||
|  |             </div> | ||||||
|  |             @enderror | ||||||
|  |         HTML; | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue