Skip to content

Commit a1b37c1

Browse files
committed
Added Create.vue
1 parent aac5f04 commit a1b37c1

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<template>
2+
<div>
3+
<h1>New {{{ title }}}</h1>
4+
5+
<div v-if="loading" class="alert alert-info" role="status">Loading...</div>
6+
<div v-if="error" class="alert alert-danger" role="alert"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> \{{ error }}</div>
7+
8+
<{{{titleUcFirst}}}Form :handle-submit="create" :values="item" :errors="violations"></{{{titleUcFirst}}}Form>
9+
<router-link :to="{ name: '{{{titleUcFirst}}}List' }" class="btn btn-default">Back to list</router-link>
10+
</div>
11+
</template>
12+
13+
<script>
14+
import {{{titleUcFirst}}}Form from './Form.vue';
15+
import { createNamespacedHelpers } from 'vuex';
16+
17+
const { mapActions, mapGetters } = createNamespacedHelpers('{{{lc}}}/create');
18+
19+
export default {
20+
components: {
21+
{{{titleUcFirst}}}Form
22+
},
23+
data: function() {
24+
return {
25+
item: {}
26+
}
27+
},
28+
computed: mapGetters([
29+
'error',
30+
'loading',
31+
'created',
32+
'violations'
33+
]),
34+
methods: {
35+
create: function(item) {
36+
this.$store.dispatch('{{{lc}}}/create/create', item);
37+
}
38+
},
39+
watch: {
40+
created: function (created) {
41+
if (created) {
42+
this.$router.push({ name: '{{{titleUcFirst}}}Update', params: { id: created['@id']} });
43+
}
44+
}
45+
}
46+
}
47+
</script>

templates/vue/components/foo/Form.vue

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<template>
2+
<form @submit.prevent="handleSubmit(values)">
3+
{{#each formFields}}
4+
<div :class="{ 'form-group': true, 'has-error': (errors && errors.{{{ name }}}) }">
5+
<label for="{{{ lc }}}_{{{ name }}}" class="control-label">{{{ name }}}</label>
6+
<input v-model="values.{{{ name }}}" type="{{{ type }}}" {{#if step}} step="{{{ step }}}"{{/if}} placeholder="{{{ description }}}" {{#if required}}required="true"{{/if}} id="{{{ lc }}}_{{{ name }}}" class="form-control" />
7+
<span v-if="errors && errors.{{{ name }}}" class="help-block" id="{{{ lc }}}_{{{ name }}}_helpBlock">\{{ errors.{{{ name }}} }}</span>
8+
</div>
9+
{{/each}}
10+
11+
<button type="submit" class="btn btn-primary">Submit</button>
12+
</form>
13+
</template>
14+
15+
<script>
16+
export default {
17+
props: {
18+
handleSubmit: {
19+
type: Function,
20+
required: true,
21+
},
22+
values: {
23+
type: Object,
24+
required: true
25+
},
26+
errors: {
27+
type: Object
28+
}
29+
}
30+
}
31+
</script>

0 commit comments

Comments
 (0)