Skip to content

Commit

Permalink
0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
benmerckx committed Jan 24, 2024
1 parent 9acb782 commit eb8245c
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
49 changes: 49 additions & 0 deletions apps/web/content/pages/docs/fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,55 @@
"fileName": "",
"language": ""
},
{
"type": "heading",
"textAlign": "left",
"level": 3,
"content": [
{
"type": "text",
"text": "`required`"
}
]
},
{
"type": "paragraph",
"textAlign": "left",
"content": [
{
"type": "text",
"text": "The `required` option will make sure the field value is not empty when saving when set to `true`."
}
]
},
{
"type": "heading",
"textAlign": "left",
"level": 3,
"content": [
{
"type": "text",
"text": "`validate`"
}
]
},
{
"type": "paragraph",
"textAlign": "left",
"content": [
{
"type": "text",
"text": "The `validate` option can be used to validate the field value using a custom function. The function should return `true` if the value is valid, `false` if it is not valid and a string if it is not valid and a message should be shown to the user."
}
]
},
{
"id": "2bOzOm5x9az8v36Esr3rHzjSmKT",
"type": "CodeBlock",
"code": "alinea.text('Hello field', {\n help: 'This field only accepts \"hello\" as a value',\n validate(value) {\n if (value !== 'hello') return 'Only \"hello\" is allowed!'\n }\n})",
"fileName": "",
"language": ""
},
{
"type": "heading",
"textAlign": "left",
Expand Down
23 changes: 23 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Changelog

## [0.6.0]

- Field validation (#369)

Introduces two new Field options available for every Field: `required` and
`validate`. The `required` option will make sure the field value is not empty
when saving. The `validate` option can be used to validate the field value
using a custom function. The function should return `true` if the value is
valid, `false` if it is not valid and a string if it is not valid and a
message should be shown to the user.

This is a breaking change, removing the `optional` property from Fields.
It was never functional.

```tsx
alinea.text('Hello field', {
help: 'This field only accepts "hello" as a value',
validate(value) {
if (value !== 'hello') return 'Only "hello" is allowed!'
}
})
```

## [0.5.12]

- Link fields using the `condition` option are now constrained with their locale
Expand Down

0 comments on commit eb8245c

Please sign in to comment.