voyager icon indicating copy to clipboard operation
voyager copied to clipboard

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

Open haexperts2020 opened this issue 3 years ago • 4 comments

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 avatar Nov 03 '21 17:11 haexperts2020

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

haexperts2020 avatar Nov 03 '21 17:11 haexperts2020

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

emptynick avatar Nov 03 '21 18:11 emptynick

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.

haexperts2020 avatar Nov 03 '21 18:11 haexperts2020

@haexperts2020

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

ruwad-co avatar Nov 10 '21 22:11 ruwad-co