11<template >
2+
23 <div class =" flex" >
34
45 <div class =" source-type-select pr-2" >
78 :reduce =" option => option.value"
89 :disabled =" ! config.localizable"
910 :clearable =" false"
10- v-model =" source"
11+ :value =" source"
12+ @input =" sourceDropdownChanged"
1113 />
1214 </div >
1315
2022
2123 <div v-else-if =" source === 'field'" class =" source-field-select" >
2224 <!-- TODO: Implement field suggestions v-select -->
23- <text-input v-model =" sourceField" :disabled =" ! config.localizable" />
25+ <text-input :value =" sourceField" @input = " sourceFieldChanged " :disabled =" ! config.localizable" />
2426 </div >
2527
2628 <component
3234 :meta =" meta.fieldMeta"
3335 :read-only =" ! config.localizable"
3436 handle =" source_value"
35- @input =" updateValue " >
37+ @input =" customValueChanged " >
3638 </component >
3739 </div >
3840 </div >
@@ -61,8 +63,6 @@ export default {
6163
6264 data () {
6365 return {
64- source: this .value .source ,
65- sourceField: this .value .source === ' field' ? this .value .value : null ,
6666 autoBindChangeWatcher: false ,
6767 changeWatcherWatchDeep: false ,
6868 allowedFieldtypes: []
@@ -71,6 +71,16 @@ export default {
7171
7272 computed: {
7373
74+ source () {
75+ return this .value .source ;
76+ },
77+
78+ sourceField () {
79+ return this .value .source === ' field'
80+ ? this .value .value
81+ : null ;
82+ },
83+
7484 componentName () {
7585 return this .config .field .type .replace (' .' , ' -' ) + ' -fieldtype' ;
7686 },
@@ -107,24 +117,6 @@ export default {
107117
108118 },
109119
110- watch: {
111-
112- source (val ) {
113- this .value .source = val;
114-
115- if (val === ' field' ) {
116- this .value .value = Array .isArray (this .sourceField ) ? this .sourceField [0 ] : this .sourceField ;
117- } else {
118- this .value .value = this .meta .defaultValue ;
119- }
120- },
121-
122- sourceField (val ) {
123- this .value .value = Array .isArray (val) ? val[0 ] : val;
124- },
125-
126- },
127-
128120 mounted () {
129121 let types = this .config .allowed_fieldtypes || [' text' , ' textarea' , ' markdown' , ' redactor' ];
130122 this .allowedFieldtypes = types .concat (this .config .merge_allowed_fieldtypes || []);
@@ -133,7 +125,20 @@ export default {
133125
134126 methods: {
135127
136- updateValue (value ) {
128+ sourceDropdownChanged (value ) {
129+ this .value .source = value;
130+
131+ if (value !== ' field' ) {
132+ this .value .value = this .meta .defaultValue ;
133+ this .meta .fieldMeta = this .meta .defaultFieldMeta ;
134+ }
135+ },
136+
137+ sourceFieldChanged (field ) {
138+ this .value .value = field;
139+ },
140+
141+ customValueChanged (value ) {
137142 let newValue = this .value ;
138143
139144 newValue .value = value;
0 commit comments