Skip to content

Commit 2ce88c7

Browse files
committed
docs for feathers-vuex-input-wrapper
1 parent 7f8ba45 commit 2ce88c7

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

docs/feathers-vuex-forms.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Working with Forms
3-
sidebarDepth: 3
3+
sidebarDepth: 4
44
---
55

66
# Working with Forms
@@ -274,3 +274,43 @@ export default {
274274
}
275275
</script>
276276
```
277+
278+
## FeathersVuexInputWrapper
279+
280+
Building on the same ideas as the FeathersVuexFormWrapper, the FeathersVuexInputWrapper reduces boilerplate for working with the clone and commit pattern on a single input. One use case for this component is implementing an "edit-in-place" workflow. The following example shows how to use the FeathersVuexInputWrapper to automatically save a record upon `blur` on text and color inputs:
281+
282+
```html
283+
<template>
284+
<div class="p-3">
285+
<FeathersVuexInputWrapper :item="user" prop="email">
286+
<template #default="{ current, prop, createClone, handler }">
287+
<input v-model="current[prop]" type="text" @focus="createClone" @blur="e => handler(e, save)" />
288+
</template>
289+
</FeathersVuexInputWrapper>
290+
291+
<FeathersVuexInputWrapper :item="user" prop="carColor">
292+
<template #default="{ current, prop, createClone, handler }">
293+
<input v-model="current[prop]" type="color" @focus="createClone" @blur="e => handler(e, save)" />
294+
</template>
295+
</FeathersVuexInputWrapper>
296+
297+
<!-- Simple readout to show that it's working. -->
298+
<pre class="bg-black text-white text-xs mt-2 p-1">{{user}}</pre>
299+
</div>
300+
</template>
301+
302+
<script>
303+
export default {
304+
name: 'InputWrapperExample',
305+
methods: {
306+
// Optionally make the event handler async.
307+
async save({ event, clone, prop, data }) {
308+
const user = clone.commit()
309+
return user.patch(data)
310+
}
311+
}
312+
}
313+
</script>
314+
```
315+
316+
Notice that in the `save` handler in the above example, the `.patch` method is called on the user, passing in the data. Because the data contains only the user property which changed, the patch request will only send the data which has changed, saving precious bandwidth.

0 commit comments

Comments
 (0)