You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> Same effect can be achieved by using [hooks](/docs/tutorial/Customization/hooks/#example-modify-the-created-object-before-it-is-saved-to-the-database). But `fillOnCreate` might be shorter and more readable.
258
274
275
+
### Suggest default value in create form
276
+
277
+
You can suggest a default value for a field in the create form which user can instantly change even before creating record.
278
+
This might be used to give user some example value or to suggest some default value.
279
+
280
+
```typescript title="./resources/apartments.ts"
281
+
exportdefault {
282
+
name: 'apartments',
283
+
fields: [
284
+
...
285
+
{
286
+
name: 'description',
287
+
//diff-add
288
+
suggestOnCreate: 'Great apartment in the heart of the city',
289
+
},
290
+
],
291
+
},
292
+
...
293
+
```
294
+
295
+
A difference between `fillOnCreate` and `suggestOnCreate`:
296
+
297
+
*`fillOnCreate` is called on the backend when the record is saved to a database. Value returned by `fillOnCreate` will be saved to the database.
298
+
*`suggestOnCreate` is just a single value that will be substituted in create form. User can change it before saving the record.
299
+
*`fillOnCreate` should be used when `showIn.create` is a `false` value because if it is `true`, the input will be shown in the create form but then(during actual save to db) it will be overwritten by the value returned by `fillOnCreate`.
300
+
*`suggestOnCreate` should be used with `showIn.create` set to true because if it is not set, the input will not be shown in the create form and default suggestion will not make sense.
0 commit comments