Skip to content

Commit

Permalink
Add support for hide_display property
Browse files Browse the repository at this point in the history
  • Loading branch information
aerni committed May 24, 2024
1 parent 4b63694 commit b8e7a38
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 129 deletions.
10 changes: 4 additions & 6 deletions resources/views/default/fields/assets.blade.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<div>
@formView('messages.display')
@formView('messages.display')

@if($field->instructions && $field->instructions_position === 'above')
@formView('messages.instructions')
@endif
</div>
@if($field->instructions && $field->instructions_position === 'above')
@formView('messages.instructions')
@endif

<div
id="{{ $field->id }}"
Expand Down
10 changes: 4 additions & 6 deletions resources/views/default/fields/captcha.blade.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<div>
@formView('messages.display')
@formView('messages.display')

@if($field->instructions && $field->instructions_position === 'above')
@formView('messages.instructions')
@endif
</div>
@if($field->instructions && $field->instructions_position === 'above')
@formView('messages.instructions')
@endif

<div
id="{{ $field->id }}"
Expand Down
86 changes: 43 additions & 43 deletions resources/views/default/fields/checkboxes.blade.php
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
<fieldset class="flex flex-col gap-y-3">
<div>
<fieldset>
<div class="flex flex-col gap-y-3">
@formView('messages.legend')

@if($field->instructions && $field->instructions_position === 'above')
@formView('messages.instructions')
@endif
</div>

<div class="{{ $field->inline ? 'flex items-start flex-wrap gap-x-6 gap-y-2' : 'flex flex-col gap-y-2' }}">
@foreach($field->options as $option => $label)
<div wire:key="{{ $field->id }}-{{ $option }}" class="flex items-start gap-x-3">
<div class="flex items-center h-5">
<input
id="{{ $field->id }}-{{ $option }}"
name="{{ $field->id }}"
value="{{ $option }}"
type="checkbox"
<div class="{{ $field->inline ? 'flex items-start flex-wrap gap-x-6 gap-y-2' : 'flex flex-col gap-y-2' }}">
@foreach($field->options as $option => $label)
<div wire:key="{{ $field->id }}-{{ $option }}" class="flex items-start gap-x-3">
<div class="flex items-center h-5">
<input
id="{{ $field->id }}-{{ $option }}"
name="{{ $field->id }}"
value="{{ $option }}"
type="checkbox"

@if($field->wire_model)
wire:model.{{ $field->wire_model }}="{{ $field->key }}"
@else
wire:model="{{ $field->key }}"
@endif
@if($field->wire_model)
wire:model.{{ $field->wire_model }}="{{ $field->key }}"
@else
wire:model="{{ $field->key }}"
@endif

@if(! $errors->has($field->key))
class="w-4 h-4 text-indigo-600 border-gray-300 rounded focus:ring-indigo-500"
@if($field->instructions)
aria-describedby="{{ $field->id }}-instructions"
@if(! $errors->has($field->key))
class="w-4 h-4 text-indigo-600 border-gray-300 rounded focus:ring-indigo-500"
@if($field->instructions)
aria-describedby="{{ $field->id }}-instructions"
@endif
@else
class="w-4 h-4 text-indigo-600 border-red-300 rounded focus:ring-red-500"
aria-invalid="true"
aria-describedby="{{ $field->id }}-error"
@endif
@else
class="w-4 h-4 text-indigo-600 border-red-300 rounded focus:ring-red-500"
aria-invalid="true"
aria-describedby="{{ $field->id }}-error"
@endif
/>
</div>
/>
</div>

<div class="text-sm leading-5">
<label
for="{{ $field->id }}-{{ $option }}"
class="font-medium {{ $errors->has($field->key) ? 'text-red-800' : 'text-gray-900' }}"
>
{{ $label }}
</label>
<div class="text-sm leading-5">
<label
for="{{ $field->id }}-{{ $option }}"
class="font-medium {{ $errors->has($field->key) ? 'text-red-800' : 'text-gray-900' }}"
>
{{ $label }}
</label>
</div>
</div>
</div>
@endforeach
</div>
@endforeach
</div>

@if($errors->has($field->key))
@formView('messages.error')
@elseif($field->instructions && $field->instructions_position === 'below')
@formView('messages.instructions')
@endif
@if($errors->has($field->key))
@formView('messages.error')
@elseif($field->instructions && $field->instructions_position === 'below')
@formView('messages.instructions')
@endif
</div>
</fieldset>
10 changes: 4 additions & 6 deletions resources/views/default/fields/default.blade.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<div>
@formView('messages.display')
@formView('messages.display')

@if($field->instructions && $field->instructions_position === 'above')
@formView('messages.instructions')
@endif
</div>
@if($field->instructions && $field->instructions_position === 'above')
@formView('messages.instructions')
@endif

<input
id="{{ $field->id }}"
Expand Down
20 changes: 10 additions & 10 deletions resources/views/default/fields/honeypot.blade.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<div class="hidden" aria-hidden="true">
<input
id="{{ $this->honeypot->id }}"
name="{{ $this->honeypot->id }}"
type="text"
wire:model="{{ $this->honeypot->key }}"
tabindex="-1"
autocomplete="off"
/>
</div>
<input
id="{{ $this->honeypot->id }}"
name="{{ $this->honeypot->id }}"
type="text"
wire:model="{{ $this->honeypot->key }}"
tabindex="-1"
autocomplete="off"
class="hidden"
aria-hidden="true"
/>
86 changes: 43 additions & 43 deletions resources/views/default/fields/radio.blade.php
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
<fieldset class="flex flex-col gap-y-3">
<div>
<fieldset>
<div class="flex flex-col gap-y-3">
@formView('messages.legend')

@if($field->instructions && $field->instructions_position === 'above')
@formView('messages.instructions')
@endif
</div>

<div class="{{ $field->inline ? 'flex items-start flex-wrap gap-x-6 gap-y-2' : 'flex flex-col gap-y-2' }}">
@foreach($field->options as $option => $label)
<div wire:key="{{ $field->id }}-{{ $option }}" class="flex items-start gap-x-3">
<div class="flex items-center h-5">
<input
id="{{ $field->id }}-{{ $option }}"
name="{{ $field->id }}"
value="{{ $option }}"
type="radio"
<div class="{{ $field->inline ? 'flex items-start flex-wrap gap-x-6 gap-y-2' : 'flex flex-col gap-y-2' }}">
@foreach($field->options as $option => $label)
<div wire:key="{{ $field->id }}-{{ $option }}" class="flex items-start gap-x-3">
<div class="flex items-center h-5">
<input
id="{{ $field->id }}-{{ $option }}"
name="{{ $field->id }}"
value="{{ $option }}"
type="radio"

@if($field->wire_model)
wire:model.{{ $field->wire_model }}="{{ $field->key }}"
@else
wire:model="{{ $field->key }}"
@endif
@if($field->wire_model)
wire:model.{{ $field->wire_model }}="{{ $field->key }}"
@else
wire:model="{{ $field->key }}"
@endif

@if(! $errors->has($field->key))
class="w-4 h-4 text-indigo-600 border-gray-300 focus:ring-indigo-500"
@if($field->instructions)
aria-describedby="{{ $field->id }}-instructions"
@if(! $errors->has($field->key))
class="w-4 h-4 text-indigo-600 border-gray-300 focus:ring-indigo-500"
@if($field->instructions)
aria-describedby="{{ $field->id }}-instructions"
@endif
@else
class="w-4 h-4 text-indigo-600 border-red-300 focus:ring-red-500"
aria-invalid="true"
aria-describedby="{{ $field->id }}-error"
@endif
@else
class="w-4 h-4 text-indigo-600 border-red-300 focus:ring-red-500"
aria-invalid="true"
aria-describedby="{{ $field->id }}-error"
@endif
/>
</div>
/>
</div>

<div class="text-sm leading-5">
<label
for="{{ $field->id }}-{{ $option }}"
class="font-medium {{ $errors->has($field->key) ? 'text-red-800' : 'text-gray-900' }}"
>
{{ $label }}
</label>
<div class="text-sm leading-5">
<label
for="{{ $field->id }}-{{ $option }}"
class="font-medium {{ $errors->has($field->key) ? 'text-red-800' : 'text-gray-900' }}"
>
{{ $label }}
</label>
</div>
</div>
</div>
@endforeach
</div>
@endforeach
</div>

@if($errors->has($field->key))
@formView('messages.error')
@elseif($field->instructions && $field->instructions_position === 'below')
@formView('messages.instructions')
@endif
@if($errors->has($field->key))
@formView('messages.error')
@elseif($field->instructions && $field->instructions_position === 'below')
@formView('messages.instructions')
@endif
</div>
</fieldset>
10 changes: 4 additions & 6 deletions resources/views/default/fields/select.blade.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<div>
@formView('messages.display')
@formView('messages.display')

@if($field->instructions && $field->instructions_position === 'above')
@formView('messages.instructions')
@endif
</div>
@if($field->instructions && $field->instructions_position === 'above')
@formView('messages.instructions')
@endif

<select
id="{{ $field->id }}"
Expand Down
10 changes: 4 additions & 6 deletions resources/views/default/fields/textarea.blade.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<div>
@formView('messages.display')
@formView('messages.display')

@if($field->instructions && $field->instructions_position === 'above')
@formView('messages.instructions')
@endif
</div>
@if($field->instructions && $field->instructions_position === 'above')
@formView('messages.instructions')
@endif

<textarea
id="{{ $field->id }}"
Expand Down
2 changes: 1 addition & 1 deletion resources/views/default/messages/display.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<label
for="{{ $field->id }}"
id="{{ $field->id }}-label"
class="block text-sm font-medium text-gray-700"
class="{{ $field->hide_display ? 'sr-only' : 'block text-sm font-medium text-gray-700 [&_+_p]:-mt-2' }}"
>
{{ $field->display }}
</label>
4 changes: 3 additions & 1 deletion resources/views/default/messages/instructions.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@if($field->instructions)
<p id="{{ $field->id }}-instructions" class="text-[13px] text-gray-500">{{ $field->instructions }}</p>
<p id="{{ $field->id }}-instructions" class="text-[13px] text-gray-500">
{{ $field->instructions }}
</p>
@endif
2 changes: 1 addition & 1 deletion resources/views/default/messages/legend.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<legend
id="{{ $field->id }}-legend"
class="text-sm font-medium text-gray-900"
class="{{ $field->hide_display ? 'sr-only' : 'text-sm font-medium text-gray-900 [&_+_p]:-mt-3' }}"
>
{{ $field->display }}
</legend>
2 changes: 2 additions & 0 deletions src/Fields/Concerns/WithDefaultProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Aerni\LivewireForms\Fields\Properties\WithDisplay;
use Aerni\LivewireForms\Fields\Properties\WithHandle;
use Aerni\LivewireForms\Fields\Properties\WithHidden;
use Aerni\LivewireForms\Fields\Properties\WithHideDisplay;
use Aerni\LivewireForms\Fields\Properties\WithId;
use Aerni\LivewireForms\Fields\Properties\WithInstructions;
use Aerni\LivewireForms\Fields\Properties\WithInstructionsPosition;
Expand All @@ -23,6 +24,7 @@ trait WithDefaultProperties
use WithDisplay;
use WithHandle;
use WithHidden;
use WithHideDisplay;
use WithId;
use WithInstructions;
use WithInstructionsPosition;
Expand Down
11 changes: 11 additions & 0 deletions src/Fields/Properties/WithHideDisplay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Aerni\LivewireForms\Fields\Properties;

trait WithHideDisplay
{
protected function hideDisplayProperty(?bool $hideDisplay = null): bool
{
return $hideDisplay ?? (bool) $this->field->get('hide_display');
}
}

0 comments on commit b8e7a38

Please sign in to comment.