thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.79k stars 2.67k forks source link

Multi checkbox displays JSON on view rather then the values from the BREAD details #5485

Open haexperts2020 opened 3 years ago

haexperts2020 commented 3 years ago

Laravel version

8.6.5

PHP version

7.4

Voyager version

1.5

Database

MySQL 8

Description

Multi checkbox displays as JSON on view rather than the values from the BREAD details

Steps to reproduce

Create a multi checkbox row with options:

{ "checked": false, "options": { "checkbox1": "Slab", "checkbox2": "Frame", "checkbox3": "Drywall", "checkbox4": "Inspection", "checkbox5": "Final" } }

Expected behavior

On the view page it should show the values of those checked the same way it shows on the browse page. Right now I have the first 2 checked and on the view page I get:

{"checkbox1":"checkbox1","checkbox2":"checkbox2"}

It should display: Slab, Frame,

Screenshots

No response

Additional context

No response

haexperts2020 commented 3 years ago

Looks like there is not a @elseif($row->type == 'multiple_checkbox') in the 'bread/read.blade.php' view, it just dumps the JSON as if it were a text field.

I added this and it's all good now:

@elseif($row->type == 'select_multiple')

    @if(property_exists($row->details, 'relationship'))

        @foreach(json_decode($dataTypeContent->{$row->field}) as $item)
            {{ $item->{$row->field}  }}
        @endforeach

    @elseif(property_exists($row->details, 'options'))
        @if (!empty(json_decode($dataTypeContent->{$row->field})))
            @foreach(json_decode($dataTypeContent->{$row->field}) as $item)
                @if (@$row->details->options->{$item})
                    {{ $row->details->options->{$item} . (!$loop->last ? ', ' : '') }}
                @endif
            @endforeach
        @else
            {{ __('voyager::generic.none') }}
        @endif
    @endif

    // new code

    @elseif($row->type == 'multiple_checkbox' && property_exists($row->details, 'options'))
    @if (@count(json_decode($dataTypeContent->{$row->field})) > 0)
        @foreach(json_decode($dataTypeContent->{$row->field}) as $item)
            @if (@$row->details->options->{$item})
                {{ $row->details->options->{$item} . (!$loop->last ? ', ' : '') }}
            @endif
        @endforeach
    @else
        {{ __('voyager::generic.none') }}
    @endif
emptynick commented 3 years ago

You mean this?

https://github.com/the-control-group/voyager/blob/1.5/resources/views/bread/browse.blade.php#L147

Edit: sorry, didn't see you mean the read view

haexperts2020 commented 3 years ago

Correct. Seems to be missing on the view/read page. I basically copy/paste that into the view.blade.php and change the $data to $dataTypeContent and it functions as expected.

ruwad-co commented 2 years ago

@haexperts2020

but why in model's table store like this {"MainBanner":"MainBanner","BoxesArea":"BoxesArea"} my options is {"checked":true,"options":{"MainBanner":"Baner","BoxesArea":"Boxes"}}