Skip to content

Commit 52bd27d

Browse files
committed
fix table field json bug
1 parent ee8112c commit 52bd27d

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/resources/views/fields/table.blade.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,20 @@
77
88
$items = old($field['name']) ? (old($field['name'])) : (isset($field['value']) ? ($field['value']) : (isset($field['default']) ? ($field['default']) : '' ));
99
10-
if(!is_array($items)) {
11-
$items = json_decode($items);
12-
}
13-
14-
if (empty($items)) {
15-
$items = '[]';
16-
} elseif ( is_string($items) && !is_array(json_decode($items)) ) {
10+
// make sure not matter the attribute casting
11+
// the $items variable contains a properly defined JSON
12+
if(is_array($items)) {
13+
if (count($items)) {
14+
$items = json_encode($items);
15+
}
16+
else
17+
{
18+
$items = '[]';
19+
}
20+
} elseif (is_string($items) && !is_array(json_decode($items))) {
1721
$items = '[]';
1822
}
23+
1924
?>
2025
<div ng-app="backpackTable" ng-controller="tableController" @include('crud::inc.field_wrapper_attributes') >
2126

@@ -25,7 +30,7 @@
2530

2631
<div class="array-container form-group">
2732

28-
<table class="table table-bordered table-striped m-b-0" ng-init="field = '#{{ $field['name'] }}'; items = {{ json_encode($items) }}; max = {{$max}}; min = {{$min}}; maxErrorTitle = '{{trans('backpack::crud.table_cant_add', ['entity' => $item_name])}}'; maxErrorMessage = '{{trans('backpack::crud.table_max_reached', ['max' => $max])}}'">
33+
<table class="table table-bordered table-striped m-b-0" ng-init="field = '#{{ $field['name'] }}'; items = {{ $items }}; max = {{$max}}; min = {{$min}}; maxErrorTitle = '{{trans('backpack::crud.table_cant_add', ['entity' => $item_name])}}'; maxErrorMessage = '{{trans('backpack::crud.table_max_reached', ['max' => $max])}}'">
2934

3035
<thead>
3136
<tr>

0 commit comments

Comments
 (0)