Skip to content

Commit

Permalink
docs: adomin json field
Browse files Browse the repository at this point in the history
  • Loading branch information
mle-moni committed Oct 7, 2024
1 parent 704c4c4 commit f20a524
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 66 additions & 0 deletions docs/src/content/docs/reference/views/models/json.md
Original file line number Diff line number Diff line change
@@ -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(),
})
),
}
```

:::

0 comments on commit f20a524

Please sign in to comment.