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
Copy file name to clipboardExpand all lines: adminforth/documentation/docs/tutorial/03-Customization/02-customFieldRendering.md
+94Lines changed: 94 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -233,6 +233,100 @@ Now you can use this component in the configuration of the resource:
233
233
}
234
234
```
235
235
236
+
### Custom record editing (updating other fields)
237
+
238
+
Sometimes a custom editor needs to update not only its own field, but also other fields of the record (for example, generate a slug from a title).
239
+
240
+
For this, custom `edit`/`create` components can emit an `update:recordFieldValue` event with the payload `{ fieldName, fieldValue }`. AdminForth will update the corresponding field in the record.
241
+
242
+
> If you emit `update:recordFieldValue` to modify a field which is hidden by `showIn.create:false` / `showIn.edit:false`, the backend will reject the request by default.
243
+
> To allow this, set the target column config to `allowModifyWhenNotShowInCreate:true` and/or `allowModifyWhenNotShowInEdit:true`.
244
+
245
+
```html title='./custom/TitleWithSlugEditor.vue'
246
+
<template>
247
+
<div class="flex flex-col gap-2">
248
+
<Input
249
+
:model-value="record[column.name]"
250
+
:placeholder="$t('Title')"
251
+
@update:model-value="onTitleChange"
252
+
/>
253
+
<Input
254
+
:model-value="record.slug"
255
+
:placeholder="$t('Slug')"
256
+
readonly
257
+
/>
258
+
</div>
259
+
</template>
260
+
261
+
<script setup lang="ts">
262
+
importInputfrom"@/afcl/Input.vue";
263
+
import type {
264
+
AdminForthResourceColumnCommon,
265
+
AdminForthResourceCommon,
266
+
AdminUser,
267
+
} from"@/types/Common";
268
+
269
+
constprops= defineProps<{
270
+
column: AdminForthResourceColumnCommon;
271
+
record: any;
272
+
meta: any;
273
+
resource: AdminForthResourceCommon;
274
+
adminUser: AdminUser;
275
+
readonly: boolean;
276
+
}>();
277
+
278
+
constemit=defineEmits([
279
+
"update:value", // update current column value
280
+
"update:recordFieldValue", // update any other field in the record
281
+
]);
282
+
283
+
functionslugify(value:string) {
284
+
return value
285
+
?.toLowerCase()
286
+
.trim()
287
+
.replace(/[^a-z0-9]+/g, "-")
288
+
.replace(/(^-|-$)+/g, "");
289
+
}
290
+
291
+
functiononTitleChange(newTitle:string) {
292
+
// update current column value
293
+
emit("update:value", newTitle);
294
+
295
+
// update another field in the record (e.g. slug)
296
+
emit("update:recordFieldValue", {
297
+
fieldName:"slug",
298
+
fieldValue:slugify(newTitle),
299
+
});
300
+
}
301
+
</script>
302
+
```
303
+
304
+
And use it in the resource configuration for both `edit` and `create` views:
305
+
306
+
```ts title='./resources/apartments.ts'
307
+
{
308
+
...
309
+
resourceId:'aparts',
310
+
columns: [
311
+
...
312
+
{
313
+
name:'title',
314
+
components: {
315
+
edit:'@@/TitleWithSlugEditor.vue',
316
+
create:'@@/TitleWithSlugEditor.vue',
317
+
},
318
+
},
319
+
{
320
+
name:'slug',
321
+
// standard input; value will be kept in sync
322
+
...
323
+
},
324
+
...
325
+
],
326
+
...
327
+
}
328
+
```
329
+
236
330
### Custom inValidity inside of the custom create/edit components
237
331
238
332
Custom componets can emit `update:inValidity` event to parent to say that the field is invalid.
Copy file name to clipboardExpand all lines: adminforth/documentation/docs/tutorial/03-Customization/04-hooks.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,7 @@ When user opens edit page, AdminForth makes a request to the backend to get the
44
44
45
45
Practically you can use `show.afterDatasourceResponse` to modify or add some data before it is displayed on the edit page.
46
46
47
-
For example [upload plugin](/docs/tutorial/Plugins/upload/) uses this hook to generate signed preview URL so user can see existing uploaded file preview in form, and at the same time database stores only original file path which might be not accessible without presigned URL.
47
+
For example [upload plugin](/docs/tutorial/Plugins/05-0-upload/) uses this hook to generate signed preview URL so user can see existing uploaded file preview in form, and at the same time database stores only original file path which might be not accessible without presigned URL.
Copy file name to clipboardExpand all lines: adminforth/documentation/docs/tutorial/03-Customization/12-security.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,7 +66,7 @@ Also you can add custom rules. For example to prevent popular words:
66
66
],
67
67
```
68
68
69
-
All rules defined in password column will be also delivered to [password reset plugin](../07-Plugins/07-email-password-reset.md) if you are using it to ensure that password reset will also respect same rules.
69
+
All rules defined in password column will be also delivered to [password reset plugin](../08-Plugins/07-email-password-reset.md) if you are using it to ensure that password reset will also respect same rules.
Copy file name to clipboardExpand all lines: adminforth/documentation/docs/tutorial/05-ListOfAdapters.md
+42Lines changed: 42 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -244,10 +244,52 @@ The RAM adapter is a simplest in-memory key-value storage. Stores data in proces
244
244
245
245
Pros:
246
246
* Simplest in use - does not reqauire any external daemon.
247
+
247
248
Cones:
248
249
* In production sutable for single-process installations only
249
250
250
251
252
+
### Redis adapter
253
+
254
+
```bash
255
+
npm i @adminforth/key-value-adapter-redis
256
+
```
257
+
258
+
Redis adapter uses in-memory RAM-based Redis database with O(1) get complexity. It is great fit for most of lightweight tasks which fit in RAM. Also capable with multi-process or replica-based installations as centralized storage. Please note that Redis daemon might be not persisted to disk during restarts without additional settings, so if persistence is critical for your task - you might need to set up it separately (for many tasks like rate-limits ephemeral data are fine
adapeter.set('test-key', 'test-value', 120); //expiry in 120 seconds
269
+
270
+
```
271
+
272
+
### LevelDB adapter
273
+
274
+
```bash
275
+
npm i @adminforth/key-value-adapter-leveldb
276
+
```
277
+
278
+
LebelDB uses disk storage with o(log(n)) get complexity. Good fit for large and/or persistent KV datasets which still require fast KV access but don't efficently fit into RAM. Please not that this is a single-process adapter only, so if you will run severall processes of admin - they will not be able to work with this adapter (>=2 processes which look at same level database might lead to unpredicted behaviour - exceptions or crashes).
279
+
280
+
You can use replicas with isolated disks, however in this case state will be also separated between replicas.
0 commit comments