diff --git a/app/View/Components/Forms/InputWithSelect.php b/app/View/Components/Forms/InputWithSelect.php index 1ce139cec..ee25b2535 100644 --- a/app/View/Components/Forms/InputWithSelect.php +++ b/app/View/Components/Forms/InputWithSelect.php @@ -14,6 +14,10 @@ class InputWithSelect extends Component public ?string $htmlId = null; + public ?string $combinedBinding = null; + + public ?string $structuredBinding = null; + public function __construct( public ?string $id = null, public ?string $name = null, @@ -72,7 +76,11 @@ class InputWithSelect extends Component $this->name = $this->modelBinding !== 'null' ? $this->modelBinding : (string) $this->id; } - // Set default option if not provided and options exist + if ($this->modelBinding && $this->modelBinding !== 'null') { + $this->combinedBinding = $this->modelBinding; + $this->structuredBinding = $this->modelBinding . 'Structured'; + } + if (is_null($this->defaultOption) && !empty($this->options)) { $this->defaultOption = array_key_first($this->options); } diff --git a/resources/views/components/forms/input-with-select.blade.php b/resources/views/components/forms/input-with-select.blade.php index f9b1f4c9b..944ce6047 100644 --- a/resources/views/components/forms/input-with-select.blade.php +++ b/resources/views/components/forms/input-with-select.blade.php @@ -8,10 +8,13 @@ defaultUnit: @js($defaultOption ?? ''), min: @js($min), max: @js($max), + validUnits: @js(array_keys($options)), @if ($modelBinding !== 'null') - combinedValue: @entangle($modelBinding), + combinedValue: @entangle($combinedBinding), + structuredValue: @entangle($structuredBinding), @else combinedValue: @js($value ?? '0'), + structuredValue: @js(['value' => $value ?? '', 'unit' => $defaultOption ?? '']), @endif })" x-ref="container"> @@ -54,7 +57,7 @@