Skip to content

Commit 28ad682

Browse files
committed
#70 add onChange method description to docs
1 parent 0d272b0 commit 28ad682

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

docs/guide/crud/field-options.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,113 @@ fieldsInfo () {
141141
::: tip INFO
142142
If `url` and `path.default` property has been set in **src/config/api.js** file, only the rest of path is required.
143143
:::
144+
145+
## `onChange`
146+
*Function*, optional. Function will be triggered after field value change in item details form. Function should have 2 arguments:
147+
- field value after change,
148+
- list with fields configuration
149+
150+
Example:
151+
152+
```vue
153+
<template>
154+
<crud
155+
:prefix="prefix"
156+
:path="path"
157+
:paths="paths"
158+
:page-title="pageTitle"
159+
:fields-info="fieldsInfo"
160+
:details-title="$t('detailsTitle')"
161+
>
162+
</crud>
163+
</template>
164+
165+
<script>
166+
import Crud from '@/utils/crud/components/Crud.vue'
167+
168+
const slugify = (text) => {
169+
const a = 'ąàáäâćęèéëêìíïîłńòóöôśùúüûźżñçßÿœæŕśńṕẃǵǹḿǘẍźḧ·/_,:;'
170+
const b = 'aaaaaceeeeeiiiilnoooosuuuuzzncsyoarsnpwgnmuxzh------'
171+
const p = new RegExp(a.split('').join('|'), 'g')
172+
173+
return text.toString().toLowerCase()
174+
.replace(/\s+/g, '-')
175+
.replace(p, c => b.charAt(a.indexOf(c)))
176+
.replace(/&/g, '-and-')
177+
.replace(/[^\w-]+/g, '')
178+
.replace(/--+/g, '-')
179+
.replace(/^-+/, '')
180+
.replace(/-+$/, '')
181+
}
182+
183+
export default {
184+
data () {
185+
return {
186+
prefix: 'crud/blog',
187+
path: 'posts',
188+
paths: {
189+
i: 'blog/posts',
190+
st: 'blog/posts',
191+
u: 'blog/posts'
192+
},
193+
pageTitle: 'blog.posts'
194+
}
195+
},
196+
computed: {
197+
fieldsInfo () {
198+
return [
199+
{
200+
text: this.$t('fields.id'),
201+
name: 'id',
202+
details: false
203+
},
204+
{
205+
type: 'input',
206+
column: 'title',
207+
text: this.$t('fields.title'),
208+
name: 'title',
209+
multiedit: false,
210+
onChange: (value, fields) => {
211+
fields.find(field => field.name === 'slug').value = slugify(value)
212+
}
213+
},
214+
{
215+
type: 'input',
216+
column: 'slug',
217+
text: this.$t('fields.slug'),
218+
name: 'slug',
219+
multiedit: false,
220+
required: false,
221+
table: false
222+
}
223+
]
224+
}
225+
},
226+
components: {
227+
Crud
228+
},
229+
i18n: {
230+
messages: {
231+
pl: {
232+
detailsTitle: 'Post',
233+
fields: {
234+
id: 'Id',
235+
title: 'Tytuł',
236+
slug: 'Slug'
237+
}
238+
},
239+
en: {
240+
detailsTitle: 'Post',
241+
fields: {
242+
id: 'Id',
243+
title: 'Title',
244+
slug: 'Slug'
245+
}
246+
}
247+
}
248+
}
249+
}
250+
251+
</script>
252+
253+
```

0 commit comments

Comments
 (0)