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: docs/feathers-vuex-form-wrapper.md
+119Lines changed: 119 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -126,3 +126,122 @@ The default slot contains only four attributes. The `clone` data can be passed
126
126
-`save`: {Function} When called, it commits the data and saves the record (with eager updating, by default. See the `eager` prop.) The save method calls `instance.save()`, internally, so you can pass a params object, if needed.
127
127
-`reset`: {Function} When called, the clone data will be reset back to the data that is currently found in the store for the same record.
128
128
-`remove`: {Function} When called, it removes the record from the API server and the Vuex store.
129
+
130
+
## Example Usage: CRUD Form
131
+
132
+
It's a pretty common scenario to have the same form handle editing and creating data. Below is a basic example of how you could use the FeathersVuexFormWrapper for this. A few things to notice about the example:
133
+
134
+
1. It uses a `Todo` Model class to create and edit todos. The `$FeathersVuex` object is available on `this` only when the [Feathers-Vuex Vue plugin](./vue-plugin.md) is used.
135
+
2. It assumes that you have a route setup with an `:id` parameter.
136
+
3. It assumes that the data has a MongoDB-style `_id` property, where an SQL-based service would probably use `id`.
Here is a minimal example showing a 'TodoEditor' component. A few things to notice about this component:
212
+
213
+
1. It's minimal on purpose to show you the important parts of working with the `FeathersVuexFormWrapper`.
214
+
1. It emits the `save`, `reset`, and `remove` events, which are connected to the `FeathersVuexFormWrapper` in the above code snippet.
215
+
1. It's not styled to keep it simple. You'll probably want to add some styles. ;)
216
+
1. The Delete button immediately emits remove, so the instance will be deleted immediately. You probably want, instead, to show a prompt or confirmation dialog to ask the user to confirm deletion.
217
+
1. This is HTML, so the button `type` is important. If you forget to add `type="button"` to a button, it will default to `type="submit"`. Clicking the button would submit the form and call the `@submit.prevent` handler on the `<form>` element. This even applies to buttons inside child components of the form. You definitely want to remember to put `type` attributes on all of your buttons.
0 commit comments