|
1 | 1 | <template> |
2 | | - <default-field :field="field" :errors="errors" :show-help-text="false"> |
3 | | - <template slot="field"> |
4 | | - <div :dir="field.rtl ? 'rtl' : 'ltr'" class="p-2 nova-tree-attach-many"> |
5 | | - <treeselect v-model="selectedValues" |
6 | | - :id="field.name" |
7 | | - :multiple="field.multiple" |
8 | | - :options="field.options" |
9 | | - :flat="field.flatten" |
10 | | - :searchable="field.searchable" |
11 | | - :always-open="field.alwaysOpen" |
12 | | - :disabled="true" |
13 | | - :sort-value-by="field.sortValueBy" |
14 | | - :placeholder="field.placeholder" |
15 | | - :max-height="field.maxHeight" |
16 | | - :value-consists-of="field.valueConsistsOf" |
17 | | - :normalizer="normalizer" |
18 | | - /> |
| 2 | + <panel-item :field="field"> |
| 3 | + <template slot="value"> |
| 4 | + <div v-for="(value, index) in field.value" :style="{ |
| 5 | + 'marginTop': index === 0 ? '0' : '6px' |
| 6 | + }"> |
| 7 | + {{ value[field.labelKey] }} |
19 | 8 | </div> |
20 | | - <help-text class="error-text mt-2 text-danger" v-if="hasErrors"> |
21 | | - {{ firstError }} |
22 | | - </help-text> |
23 | 9 | </template> |
24 | | - </default-field> |
| 10 | + </panel-item> |
25 | 11 | </template> |
26 | 12 |
|
27 | 13 | <script> |
28 | | -import { FormField, HandlesValidationErrors } from "laravel-nova"; |
29 | | -
|
30 | | -import Treeselect from "@riophae/vue-treeselect"; |
31 | | -import "@riophae/vue-treeselect/dist/vue-treeselect.css"; |
32 | | -
|
33 | 14 | export default { |
34 | | - components: {Treeselect}, |
35 | | - mixins: [FormField, HandlesValidationErrors], |
36 | | -
|
37 | | - props: ['resourceName', 'resourceId', 'field'], |
38 | | -
|
39 | | - data() |
40 | | - { |
41 | | - return { |
42 | | - selectedValues: null, |
43 | | - }; |
44 | | - }, |
45 | | - methods: { |
46 | | - normalizer( node ) |
47 | | - { |
48 | | - return { |
49 | | - id: node[this.field.idKey], |
50 | | - label: node[this.field.labelKey], |
51 | | - children: node.hasOwnProperty(this.field.childrenKey) |
52 | | - && node[this.field.childrenKey].length > 0 |
53 | | - ? node[this.field.childrenKey] |
54 | | - : false |
55 | | - } |
56 | | - }, |
57 | | - setInitialValue() |
58 | | - { |
59 | | - let baseUrl = '/nova-vendor/nova-nested-tree-attach-many/'; |
60 | | -
|
61 | | - if( this.resourceId ) |
62 | | - { |
63 | | - const url = [ |
64 | | - baseUrl + this.resourceName, |
65 | | - this.resourceId, |
66 | | - "attached", |
67 | | - this.field.attribute, |
68 | | - this.field.idKey |
69 | | - ]; |
70 | | -
|
71 | | - Nova.request( url.join( "/" ) ) |
72 | | - .then( ( data ) => |
73 | | - { |
74 | | - if(!this.field.multiple) |
75 | | - { |
76 | | - this.selectedValues = data.data || undefined; |
77 | | - } |
78 | | - else |
79 | | - { |
80 | | - this.selectedValues = data.data || []; |
81 | | - } |
82 | | - } ); |
83 | | - } |
84 | | - }, |
85 | | - fill( formData ) |
86 | | - { |
87 | | - formData.append( this.field.attribute, JSON.stringify( this.selectedValues ) ) |
88 | | - }, |
89 | | - }, |
90 | | - computed:{ |
91 | | - hasErrors: function() { |
92 | | - return this.errors.errors.hasOwnProperty(this.field.attribute); |
93 | | - }, |
94 | | - firstError: function() { |
95 | | - return this.errors.errors[this.field.attribute][0] |
96 | | - }, |
97 | | - } |
| 15 | + props: ['resourceName', 'resourceId', 'field'] |
98 | 16 | } |
99 | 17 | </script> |
0 commit comments