Skip to content

Commit b3f1ea3

Browse files
author
ziming
committed
add more default modes options
1 parent 6c23069 commit b3f1ea3

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"homepage": "https://github.com/ziming/json-field-for-backpack",
1818
"keywords": ["Laravel", "Backpack", "Backpack for Laravel", "Addon", "Admin Panel", "Json", "Field"],
1919
"require": {
20+
"ext-json": "*",
2021
"backpack/crud": "^4.1.0|^5.0"
2122
},
2223
"autoload": {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
if (is_array($value) || is_object($value) ) {
1717
$value = json_encode($value);
1818
}
19+
20+
// bug in laravel @json blade directive, it cannot accept an array of more than 3 items directly.
21+
// hence the need to declare a variable here 1st then pass to @json later.
22+
$defaultModes = ['form', 'tree', 'code', 'preview', 'text'];
1923
@endphp
2024

2125
@if ($crud->checkIfFieldIsFirstOfItsType($field, $fields))
@@ -55,7 +59,7 @@
5559
const hiddenField = document.getElementById('{{ $field['name'] }}');
5660
hiddenField.value = window['editor_{{ $field['name'] }}'].getText();
5761
},
58-
modes: @json($field['modes'] ?? ['form', 'tree', 'code']),
62+
modes: @json($field['modes'] ?? $defaultModes),
5963
};
6064
6165
window['editor_{{ $field['name'] }}'] = new JSONEditor(container, options, JSON.parse(jsonString));

0 commit comments

Comments
 (0)