Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Ivona <[email protected]>
  • Loading branch information
fabio-ivona committed Feb 18, 2021
1 parent 19f7b36 commit 730dfb4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
7 changes: 3 additions & 4 deletions resources/views/radio.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,20 @@
*
*/
$radio_id = $computed_id();
$radio_id = "$radio_id-$value";
$radio_id = $computed_id()."-".$original_value();
?>


@if($readonly)
<input type="hidden" name="{{$name()}}" value="{{$value_checked}}">
<input type="hidden" name="{{$name()}}" value="{{$original_value()}}">
@endif

<div class="custom-control {{!empty($label??$slot->isNotEmpty())?'d-flex':''}} {{$custom_class}} {{$containerClass}} {{$inline?'custom-control-inline':''}}">
<input
type="radio"
id="{{$radio_id}}"
name="{{$name()}}"
value="{{$value_checked}}"
value="{{$original_value()}}"
{{$attributes->merge(['class' => "custom-control-input"])}}
{{$is_checked()?'checked':''}}
{{$readonly?'disabled':''}}
Expand Down
18 changes: 13 additions & 5 deletions src/Traits/HasValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ trait HasValue

protected $value;

public function computed_value($default = '')
public function original_value(): string
{
return $this->value;
}

public function computed_value(
$default = ''
) {
return $this->old_value(
$this->draft_value(
$this->model_value(
Expand All @@ -28,8 +34,9 @@ public function computed_value($default = '')
}


public function model_value($default = '')
{
public function model_value(
$default = ''
) {
$model = $this->model();

if (empty($model)) {
Expand All @@ -39,8 +46,9 @@ public function model_value($default = '')
return data_get($model, $this->dotted_field_name(), $default);
}

public function component_value($default = null)
{
public function component_value(
$default = null
) {
return $this->value ?? $default;
}

Expand Down
9 changes: 6 additions & 3 deletions src/View/Components/Radio.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class Radio extends Component
public string $custom_class = 'custom-radio';
public bool $inline;
public bool $readonly;
public string $modelField;
public ?string $label;
private bool $checked;

Expand Down Expand Up @@ -61,8 +60,12 @@ public function is_checked(): bool
return true;
}

$computed_value = $this->computed_value($this->checked);
$computed_value = $this->old_value(
$this->draft_value(
$this->model_value()
)
);

return $computed_value == $this->value;
return $computed_value === $this->value;
}
}

0 comments on commit 730dfb4

Please sign in to comment.