Skip to content

Commit ffff8d8

Browse files
Merge pull request #57 from JSON-ms/dev
Schemas, Rules, Default values, Range selector
2 parents 60865e5 + abf9e3a commit ffff8d8

17 files changed

Lines changed: 400 additions & 126 deletions

docs/interface.md

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ For instance:
7373
- `number`: A numeric input field for entering numbers.
7474
- `rating`: A component that allows users to provide feedback or evaluate an item using a star or point system, typically ranging from 1 to 5, visually represented through icons or bars.
7575
- `slider`: A slider component that allows you to select a number.
76+
- `range`: A range slider component that allows you to select a range of number.
7677
- `select`: A dropdown menu that allows users to choose one or multiple items from a predefined list.
7778
- `checkbox`: A binary input that allows users to select one or more items from a set of choices.
7879
- `radio`: A set of options where only one can be selected at a time, typically displayed as buttons.
@@ -87,25 +88,44 @@ For instance:
8788
#### All Field Properties:
8889
- `type`: Specifies a supported field type as defined earlier.
8990
- `label`: The title that will be displayed within the field.
91+
- `default`: A optional default value for the current field.
9092
- `multiple`: A boolean value that indicates whether the field can accept multiple values (e.g., for `select`, `checkbox` or `file` types).
93+
- `icon`: (Optional) An icon that will be displayed next to the menu item.
9194
- `accept`: For `file` field only. It takes as its value a comma-separated list of one or more file types. You can add file extensions `*.jpg,*.gif` or even mime types `application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document`.
95+
- `rules`: An optional list of rules (regex) to be applied to the field. See rules section for explanation.
9296
- `prepend`: An optional string that will be displayed before the input field.
9397
- `append`: An optional string that will be displayed after the input field.
9498
- `prepend-inner`: An optional string that will be displayed inside and before the input field. Can be used with `string`, `number`, `select`, `textarea` and `date` fields.'
9599
- `append-inner`: An optional string that will be displayed inside and after the input field. Can be used with `string`, `number`, `select`, `textarea` and `date` fields.'
96100
- `hint`: An optional string that provides additional information or guidance to the user about the field, displayed below the field.
97-
- `icon`: (Optional) An icon that will be displayed next to the menu item.
98101
- Make sure to prefix all icons with "mdi-". For instance: mdi-check will show the "check" icon.
99102
- Documentation: https://pictogrammers.com/library/mdi/
100103
- `required`: (Optional) It ensures that the user must provide a value, preventing the form from being submitted until the field is completed.
101104
- `fields`: This is applicable only for `array` and `node` types. You can use any supported type here, and you can nest sub-arrays as needed to create complex data structures and hierarchies.
102105
- `items`: This is applicable only for `select`, `checkbox` and `radio` types. You can list all available values or even use an enum.
103-
- `min`: An optional minimum number. Works with `number` and `slider` fields.
104-
- `max`: An optional maximum number. Works with `number` and `slider` fields.
106+
- `min`: An optional minimum number. Works with `array`, `number`, `slider` and `range` fields.
107+
- `max`: An optional maximum number. Works with `array`, `number`, `slider` and `range` fields.
105108
- `length`: An optional length amount of stars in `rating` field.
106-
- `step`: An optional incremental amount when using `number` and `slider` fields.
109+
- `step`: An optional incremental amount when using `number`, `slider` and `range` fields.
107110
- `half-increments`: (Optional) Allows half-increments of stars when using the `rating` field.
108111

112+
### Rules
113+
114+
You can create validation for your form using regex expressions. Here's an example of two rules for a field `title`. It will validate that the value of the title starts with `abc` and ends with `123`.
115+
116+
```yaml
117+
title:
118+
type: string
119+
label: Title
120+
rules:
121+
- regex: /^abc/
122+
message: The string must start with abc
123+
- regex: /123$/
124+
message: The string must end with 123
125+
```
126+
127+
Fields `number` automatically includes a rule for checking number values.
128+
109129
### Paths
110130

111131
If you want to synchronize your sections with your website or app pages, you need to define paths. By default, if you do not set this parameter, JSON.ms will still try to find a route name matching the section key (in this case, "about").
@@ -202,3 +222,31 @@ Here's an example of a field using an enum:
202222
label: Title
203223
items: enums.countries
204224
```
225+
226+
## Schemas
227+
228+
Reusable schemas (fieldset) are a powerful feature that allows you to define a set of predefined fields that can be referenced multiple times throughout your interface. This promotes consistency in your data definitions and reduces redundancy, making your code cleaner and easier to maintain.
229+
230+
```yaml
231+
schemas:
232+
meta:
233+
title:
234+
type: string
235+
label: Title
236+
required: true
237+
description:
238+
type: string
239+
label: Description
240+
```
241+
242+
You can later use these schemas as a field type like any other widget using the `schemas.[NAME]` syntax.
243+
244+
Here's an example of a field using an schema:
245+
246+
```yaml
247+
meta:
248+
type: schemas.meta
249+
label: Meta data # (Optional) A title for your collapsable group
250+
collapsable: true # Make it a collapsable group
251+
collapsed: true # Make it collapsed by default
252+
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@json.ms/www",
33
"private": true,
44
"type": "module",
5-
"version": "1.1.10",
5+
"version": "1.1.11",
66
"scripts": {
77
"dev": "vite --host",
88
"build": "run-p type-check \"build-only {@}\" --",

src/assets/default-interface-structure.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
},
88
"enums": {
99

10+
},
11+
"schemas": {
12+
1013
},
1114
"sections": {
1215

src/assets/example-interface.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ enums:
3333
mx: Mexico
3434

3535

36+
# Reusable Schemas:
37+
# This feature allows you to define a schema of fields that can
38+
# be reused throughout your document. A good example of schemas
39+
# could be meta titles and descriptions for your web pages.
40+
schemas:
41+
meta:
42+
title:
43+
type: string
44+
label: Title
45+
required: true
46+
description:
47+
type: string
48+
label: Description
49+
50+
3651
# App Sections and Fields:
3752
# Outline the various sections of your data, detailing the
3853
# specific fields within each section. This allows for a structured
@@ -43,6 +58,8 @@ sections:
4358
label: Home page
4459
icon: mdi-account
4560
fields:
61+
meta:
62+
type: schemas.meta
4663
title:
4764
type: i18n
4865
label: Title

src/components/Docs.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const applyEditors = (language = 'yaml') => {
3737
showFoldWidgets: false,
3838
showGutter: false,
3939
fontSize: 14,
40+
tabSize: 2,
4041
});
4142
}
4243
}

0 commit comments

Comments
 (0)