diff --git a/docs/src/assets/images/reference/models/json/json.png b/docs/src/assets/images/reference/models/json/json.png new file mode 100644 index 0000000..5958b40 Binary files /dev/null and b/docs/src/assets/images/reference/models/json/json.png differ diff --git a/docs/src/assets/images/reference/models/json/table_json.png b/docs/src/assets/images/reference/models/json/table_json.png new file mode 100644 index 0000000..5c5c005 Binary files /dev/null and b/docs/src/assets/images/reference/models/json/table_json.png differ diff --git a/docs/src/assets/images/reference/models/json/table_json_opened.png b/docs/src/assets/images/reference/models/json/table_json_opened.png new file mode 100644 index 0000000..5af59bd Binary files /dev/null and b/docs/src/assets/images/reference/models/json/table_json_opened.png differ diff --git a/docs/src/content/docs/reference/views/models/json.md b/docs/src/content/docs/reference/views/models/json.md new file mode 100644 index 0000000..78077b9 --- /dev/null +++ b/docs/src/content/docs/reference/views/models/json.md @@ -0,0 +1,66 @@ +--- +title: Json field +sidebar: + order: 1013 + badge: New +description: Adomin json field reference +--- + +In the table page, a json field will look like this + +![field image](~/assets/images/reference/models/json/table_json.png) + +When you click on the "open" button + +![field image](~/assets/images/reference/models/json/table_json_opened.png) + +In the create / edit page + +![edit field image](~/assets/images/reference/models/json/json.png) + +## Config + +### validation + +Optionnal, a Vine validation schema to enforce on the json field + +e.g. + +```ts +const fieldValidationSchema = vine.compile( + vine.object({ + color: vine.string(), + isBeautiful: vine.boolean(), + age: vine.number().optional(), + }) +) +``` + +:::tip +By default, the json field is not searchable/sortable, but you can override this behavior by using the `sqlFilter` and `sqlSort` options (for `sqlFilter` use the bindings parameter to pass values to the sql query to prevent sql injection) + +```ts +{ + type: 'json', + label: 'Paramètres', + nullable: true, + sqlFilter: (input) => { + if (!input) return 'true' + + return { + sql: `settings->>'color' like '%' || ? || '%'`, + bindings: [input], + } + }, + sqlSort: (ascDesc) => `settings->>'color' ${ascDesc}`, + validation: vine.compile( + vine.object({ + color: vine.string(), + isBeautiful: vine.boolean(), + age: vine.number().optional(), + }) + ), +} +``` + +:::