@startupjs-ui/form 0.1.13 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.mdx +51 -22
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.1.17](https://github.com/startupjs/startupjs-ui/compare/v0.1.16...v0.1.17) (2026-02-12)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @startupjs-ui/form
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [0.1.16](https://github.com/startupjs/startupjs-ui/compare/v0.1.15...v0.1.16) (2026-02-10)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @startupjs-ui/form
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
## [0.1.13](https://github.com/startupjs/startupjs-ui/compare/v0.1.12...v0.1.13) (2026-02-03)
|
|
7
23
|
|
|
8
24
|
**Note:** Version bump only for package @startupjs-ui/form
|
package/README.mdx
CHANGED
|
@@ -5,7 +5,7 @@ import { Sandbox } from '@startupjs-ui/docs'
|
|
|
5
5
|
|
|
6
6
|
# Form
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Form renders a set of inputs based on a JSON Schema-compatible field definition. It wraps `ObjectInput` and adds support for custom input types, validation, and sharing props through context.
|
|
9
9
|
|
|
10
10
|
```jsx
|
|
11
11
|
import { Form } from 'startupjs-ui'
|
|
@@ -42,11 +42,29 @@ return (
|
|
|
42
42
|
)
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
+
## Props
|
|
46
|
+
|
|
47
|
+
- **$value** (required) -- a scoped model binding for form values
|
|
48
|
+
- **fields** -- an object describing the form fields (JSON Schema-compatible)
|
|
49
|
+
- **$fields** -- a reactive scoped model for fields (overrides `fields`)
|
|
50
|
+
- **order** -- an array of field names that controls the rendering order
|
|
51
|
+
- **row** -- when `true`, renders the inputs in a horizontal row
|
|
52
|
+
- **validate** -- set to `true` for automatic validation, or pass a `useValidate()` hook instance for manual control
|
|
53
|
+
- **errors** -- an explicit errors object to display
|
|
54
|
+
- **$errors** -- a reactive scoped model for errors (managed by validation)
|
|
55
|
+
- **customInputs** -- an object mapping custom input type keys to input components
|
|
56
|
+
- **disabled** -- set to `true` to disable all form interactions
|
|
57
|
+
- **readonly** -- set to `true` to render all fields as read-only
|
|
58
|
+
- **style** -- custom styles for the outer wrapper
|
|
59
|
+
- **inputStyle** -- custom styles for the inner input container
|
|
60
|
+
|
|
61
|
+
Any additional props are passed through to custom inputs via the `useFormProps()` hook.
|
|
62
|
+
|
|
45
63
|
## Custom inputs
|
|
46
64
|
|
|
47
|
-
Pass custom inputs to the
|
|
65
|
+
Pass custom inputs to the Form using the `customInputs` prop.
|
|
48
66
|
|
|
49
|
-
Inside custom inputs you can access Form's props using the `useFormProps` hook.
|
|
67
|
+
Inside custom inputs you can access the Form's extra props using the `useFormProps` hook.
|
|
50
68
|
|
|
51
69
|
```jsx
|
|
52
70
|
import { observer } from 'startupjs'
|
|
@@ -85,9 +103,9 @@ const CustomAgeInput = observer(({ $value, ...props }) => {
|
|
|
85
103
|
|
|
86
104
|
### Adding custom inputs globally
|
|
87
105
|
|
|
88
|
-
You can add custom inputs globally by creating a plugin
|
|
106
|
+
You can add custom inputs globally by creating a plugin that uses the client's `customFormInputs` hook.
|
|
89
107
|
|
|
90
|
-
|
|
108
|
+
Return an object with the custom inputs from this hook.
|
|
91
109
|
|
|
92
110
|
```jsx
|
|
93
111
|
// startupjs.config.js
|
|
@@ -120,7 +138,7 @@ createPlugin({
|
|
|
120
138
|
})
|
|
121
139
|
```
|
|
122
140
|
|
|
123
|
-
|
|
141
|
+
The JSX will then look like this:
|
|
124
142
|
|
|
125
143
|
```jsx
|
|
126
144
|
import { observer } from 'startupjs'
|
|
@@ -135,7 +153,7 @@ function App () {
|
|
|
135
153
|
fields={{
|
|
136
154
|
age: {
|
|
137
155
|
type: 'number',
|
|
138
|
-
input: 'age'
|
|
156
|
+
input: 'age',
|
|
139
157
|
description: 'Your age (18+)'
|
|
140
158
|
}
|
|
141
159
|
}}
|
|
@@ -144,21 +162,21 @@ function App () {
|
|
|
144
162
|
}
|
|
145
163
|
```
|
|
146
164
|
|
|
147
|
-
|
|
148
|
-
In the form
|
|
149
|
-
and
|
|
165
|
+
Pass all necessary constants as options to the plugin (in this case, `minAge`).
|
|
166
|
+
In the form, define the `type` according to the actual data type (in this case, `number`),
|
|
167
|
+
and add an `input` property with the custom type key from the plugin (in this case, `'age'`).
|
|
150
168
|
|
|
151
|
-
## JSON
|
|
169
|
+
## JSON Schema compatibility
|
|
152
170
|
|
|
153
|
-
`fields` prop is
|
|
171
|
+
The `fields` prop is JSON Schema-compatible.
|
|
154
172
|
|
|
155
|
-
If you
|
|
173
|
+
If you need to specify both the JSON Schema type and a custom input type, use the `input` property in addition to the `type` property within a field definition.
|
|
156
174
|
|
|
157
175
|
## Validation
|
|
158
176
|
|
|
159
|
-
By default
|
|
177
|
+
By default, Form does not run any validation.
|
|
160
178
|
|
|
161
|
-
|
|
179
|
+
Pass `validate={true}` to use the `fields` schema to automatically validate the form and reactively display any errors.
|
|
162
180
|
|
|
163
181
|
```jsx
|
|
164
182
|
<Form validate={true} />
|
|
@@ -166,21 +184,21 @@ By passing `validate={true}` it will use the `fields` (which is json-schema comp
|
|
|
166
184
|
|
|
167
185
|
### `useValidate()`
|
|
168
186
|
|
|
169
|
-
To trigger validation manually, use `useValidate()` hook.
|
|
187
|
+
To trigger validation manually, use the `useValidate()` hook.
|
|
170
188
|
|
|
171
|
-
It
|
|
189
|
+
It returns a `validate` function that you can call to run validation. It returns `true` if validation passes (there are no errors).
|
|
172
190
|
|
|
173
|
-
If there are errors, they
|
|
191
|
+
If there are errors, they are available on `validate.hasErrors` (`true` or `false`) and `validate.errors` (an object mapping field names to arrays of error messages: `{ name: ['This field is required'], age: ['must be above 18'] }`).
|
|
174
192
|
|
|
175
193
|
### `useValidate({ always: true })`
|
|
176
194
|
|
|
177
|
-
By default, only after the first manual `validate()` call
|
|
195
|
+
By default, the Form only starts showing errors after the first manual `validate()` call, then updates them reactively on each change.
|
|
178
196
|
|
|
179
|
-
If you want the
|
|
197
|
+
If you want the Form to show errors right away and update them reactively as soon as it renders, pass `always: true` to the hook.
|
|
180
198
|
|
|
181
|
-
This
|
|
199
|
+
This effectively makes the Form behave as if `validate={true}` was passed, but also gives you access to the `validate` function for manual calls when needed.
|
|
182
200
|
|
|
183
|
-
### Example with
|
|
201
|
+
### Example with validation
|
|
184
202
|
|
|
185
203
|
```jsx
|
|
186
204
|
import { $ } from 'startupjs'
|
|
@@ -207,6 +225,17 @@ export default function App () {
|
|
|
207
225
|
}
|
|
208
226
|
```
|
|
209
227
|
|
|
228
|
+
## Hooks
|
|
229
|
+
|
|
230
|
+
In addition to `useFormProps` and `useValidate` described above, Form also exports:
|
|
231
|
+
|
|
232
|
+
- **useFormFields()** -- returns the current form fields
|
|
233
|
+
- **useFormFields$()** -- returns a reactive scoped model for the form fields
|
|
234
|
+
|
|
235
|
+
```jsx
|
|
236
|
+
import { useFormProps, useValidate, useFormFields, useFormFields$ } from 'startupjs-ui'
|
|
237
|
+
```
|
|
238
|
+
|
|
210
239
|
## Sandbox
|
|
211
240
|
|
|
212
241
|
export function SandboxWrapper () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startupjs-ui/form",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"type": "module",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@startupjs-ui/core": "^0.1.11",
|
|
12
|
-
"@startupjs-ui/input": "^0.1.
|
|
13
|
-
"@startupjs-ui/object-input": "^0.1.
|
|
12
|
+
"@startupjs-ui/input": "^0.1.17",
|
|
13
|
+
"@startupjs-ui/object-input": "^0.1.17",
|
|
14
14
|
"lodash": "^4.17.20"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
@@ -18,5 +18,5 @@
|
|
|
18
18
|
"react-native": "*",
|
|
19
19
|
"startupjs": "*"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "902cb7536d017b53dc268cc54e8e54818279744c"
|
|
22
22
|
}
|