components input / InputLocale

This commit is contained in:
pushuo 2023-03-09 15:53:42 +08:00 committed by Edward Yang
parent 3a456ceb58
commit af6f079b43
5 changed files with 12 additions and 4 deletions

View File

@ -16,19 +16,22 @@ class Input extends Component
public string $width;
public string $placeholder;
public string $type;
public string $step;
public bool $required;
public function __construct(string $name, string $title, string $value, bool $required = false, string $error = '', string $width = '400', string $type = 'text', string $step = '')
public function __construct(string $name, string $title, string $value, bool $required = false, string $error = '', string $width = '400', string $type = 'text', string $step = '', string $placeholder = '')
{
$this->name = $name;
$this->title = $title;
$this->value = html_entity_decode($value, ENT_QUOTES);
$this->error = $error;
$this->width = $width;
$this->placeholder = $placeholder;
$this->type = $type;
$this->step = $step;
$this->required = $required;

View File

@ -14,15 +14,18 @@ class InputLocale extends Component
public string $width;
public string $placeholder;
public $value;
public bool $required;
public function __construct(string $name, string $title, $value, string $width = '400', bool $required = false)
public function __construct(string $name, string $title, $value, string $width = '400', bool $required = false, string $placeholder = '')
{
$this->name = $name;
$this->title = $title;
$this->width = $width;
$this->placeholder = $placeholder;
$this->value = $value;
$this->required = $required;
}

View File

@ -3,7 +3,7 @@
<div class="d-flex wp-{{ $width }}">
<span class="input-group-text wp-100 px-1" id="basic-addon1">{{ $locale['name'] }}</span>
<input type="text" name="{{ $formatName($locale['code']) }}" value="{{ $formatValue($locale['code']) }}"
class="form-control short" placeholder="{{ $locale['name'] }}" @if ($required) required @endif>
class="form-control short" placeholder="{{ $placeholder ?: $locale['name'] }}" @if ($required) required @endif>
<span class="invalid-feedback w-auto"
style="white-space:nowrap;">{{ __('common.error_required', ['name' => $title]) }}</span>
</div>

View File

@ -1,7 +1,7 @@
<x-admin::form.row :title="$title" :required="$required">
<input type="{{ $type }}" name="{{ $name }}"
class="form-control wp-{{ $width }} {{ $error ? 'is-invalid' : '' }}" value="{{ $value }}"
placeholder="{{ $title }}" @if ($required) required @endif @if ($step) step="{{ $step }}" @endif>
placeholder="{{ $placeholder ?: $title }}" @if ($required) required @endif @if ($step) step="{{ $step }}" @endif>
<span class="invalid-feedback" role="alert">
@if ($error)
{{ $error }}

View File

@ -21,6 +21,7 @@
<x-admin-form-input
:name="$column['name']"
:title="$column['label']"
:placeholder="$column['placeholder'] ?? ''"
:error="$errors->first($column['name'])"
:required="$column['required'] ? true : false"
:value="old($column['name'], $column['value'] ?? '')" />
@ -30,6 +31,7 @@
<x-admin-form-input-locale
:name="$column['name'].'.*'"
:title="$column['label']"
:placeholder="$column['placeholder'] ?? ''"
:error="$errors->first($column['name'])"
:required="$column['required'] ? true : false"
:value="old($column['name'], $column['value'] ?? '')" />