mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-03 16:51:40 +09:00
Implement options and default value in select/checkbox/radio extra vars
This commit is contained in:
parent
db4103b732
commit
782df3a42e
3 changed files with 41 additions and 11 deletions
|
|
@ -150,7 +150,6 @@ class Value
|
|||
'type' => $this->type,
|
||||
'value' => self::_getTypeValue($this->type, $this->value),
|
||||
'default' => self::_getTypeValue($this->type, $this->default),
|
||||
'options' => $this->getOptions(),
|
||||
'input_name' => $this->parent_type === 'document' ? ('extra_vars' . $this->idx) : ($this->input_name ?: $this->eid),
|
||||
'input_id' => $this->input_id ?: '',
|
||||
]);
|
||||
|
|
@ -158,13 +157,24 @@ class Value
|
|||
}
|
||||
|
||||
/**
|
||||
* Check if the current value can have options.
|
||||
* Get the default value.
|
||||
*
|
||||
* @return bool
|
||||
* @return mixed
|
||||
*/
|
||||
public function canHaveOptions(): bool
|
||||
public function getDefaultValue()
|
||||
{
|
||||
return isset(self::OPTION_TYPES[$this->type]);
|
||||
if (!$this->canHaveOptions())
|
||||
{
|
||||
return $this->default;
|
||||
}
|
||||
elseif (is_array($this->options))
|
||||
{
|
||||
return $this->default;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -193,6 +203,16 @@ class Value
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current value can have options.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canHaveOptions(): bool
|
||||
{
|
||||
return isset(self::OPTION_TYPES[$this->type]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next temporary ID.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,10 +1,15 @@
|
|||
@php
|
||||
$has_value = is_array($value);
|
||||
$default_value = $definition->getDefaultValue();
|
||||
@endphp
|
||||
|
||||
@if ($parent_type === 'member')
|
||||
<div class="rx_ev_{{ $type }}" style="padding-top:5px">
|
||||
@foreach ($default ?? [] as $v)
|
||||
@foreach ($definition->getOptions() as $v)
|
||||
@php
|
||||
$column_suffix = $type === 'checkbox' ? '[]' : '';
|
||||
$tempid = $definition->getNextTempID();
|
||||
$is_checked = is_array($value) && in_array(trim($v), $value);
|
||||
$is_checked = $has_value ? in_array($v, $value) : ($v === $default_value);
|
||||
@endphp
|
||||
<label for="{{ $tempid }}">
|
||||
<input type="{{ $type }}" name="{{ $input_name . $column_suffix }}"
|
||||
|
|
@ -19,11 +24,11 @@
|
|||
</div>
|
||||
@else
|
||||
<ul class="rx_ev_{{ $type }}">
|
||||
@foreach ($default ?? [] as $v)
|
||||
@foreach ($definition->getOptions() as $v)
|
||||
@php
|
||||
$column_suffix = $type === 'checkbox' ? '[]' : '';
|
||||
$tempid = $definition->getNextTempID();
|
||||
$is_checked = is_array($value) && in_array(trim($v), $value);
|
||||
$is_checked = $has_value ? in_array($v, $value) : ($v === $default_value);
|
||||
@endphp
|
||||
<li>
|
||||
<input type="{{ $type }}" name="{{ $input_name . $column_suffix }}"
|
||||
|
|
|
|||
|
|
@ -1,10 +1,15 @@
|
|||
@php
|
||||
$has_value = is_array($value);
|
||||
$default_value = $definition->getDefaultValue();
|
||||
@endphp
|
||||
|
||||
<select name="{{ $input_name }}"
|
||||
id="{{ $input_id }}"|if="$input_id" class="select rx_ev_select"
|
||||
style="{{ $definition->style }}"|if="$definition->style"
|
||||
@required(toBool($definition->is_required))
|
||||
@disabled(toBool($definition->is_disabled))
|
||||
@readonly(toBool($definition->is_readonly))>
|
||||
@foreach ($default ?: [] as $v)
|
||||
<option value="{{ $v }}" @selected(is_array($value) && in_array(trim($v), $value))>{{ $v }}</option>
|
||||
@foreach ($definition->getOptions() as $v)
|
||||
<option value="{{ $v }}" @selected($has_value ? in_array($v, $value) : ($v === $default_value))>{{ $v }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue