11<template >
2- <div class =" tcs-field" >
3- <textarea v-if =" is_textarea "
2+ <div class =" tcs-field" :id = " 'field-' + name " >
3+ <textarea v-if =" field.type === 'text' && field.max_length > 500 "
44 :name =" name"
5- :placeholder =" field. label"
5+ :placeholder =" label"
66 :required =" field.required"
77 :maxlength =" field.max_length || 255"
88 :value =" value"
99 @input =" changed"
1010 rows =" 5" >
1111 </textarea >
12+
13+ <label v-else-if =" field.type === 'checkbox'" >
14+ <input type =" checkbox" :name =" name" :required =" field.required" :checked =" value" @change =" changed" >
15+ {{ label }}
16+ </label >
17+
18+ <label v-else-if =" field.type === 'select'" >
19+ {{ label }}
20+ <select :name =" name" :required =" field.required" @input =" changed" >
21+ <option v-for =" choice in field.choices" :value =" choice.value" :selected =" choice.value === value" >
22+ {{ choice.display_name }}
23+ </option >
24+ </select >
25+ </label >
26+
1227 <input v-else
1328 :type =" field.type"
1429 :name =" name"
15- :placeholder =" field. label"
30+ :placeholder =" label"
1631 :required =" field.required"
1732 :maxlength =" field.max_length || 255"
1833 :value =" value"
1934 @input =" changed" >
35+
36+ <div :class =" 'help-text' + (this.field.prefix ? '' : ' muted')" >
37+ {{ field.help_text }}
38+ </div >
2039 </div >
2140</template >
2241
2342<script >
2443export default {
2544 props: {
2645 field: Object ,
27- prefix: {
28- type: String ,
29- default: ' '
30- },
3146 },
3247 computed: {
3348 is_textarea : function () {
34- // TODO return this.field.type === 'text' && this.field.max_length > 500
35- return this .field .type === ' text' && this .prefix === ' attributes'
49+ return this .field .type === ' text' && this .field .max_length > 500
50+ },
51+ label : function () {
52+ return this .field .label + (this .field .required ? this .$root .get_text (' required_message' ) : ' ' )
3653 },
3754 name : function () {
38- return this .prefix + ' .' + this .field .field
55+ if (this .field .prefix ) {
56+ return this .field .prefix + ' -' + this .field .field
57+ } else {
58+ return this .field .field
59+ }
3960 },
4061 value : function () {
41- if (this .prefix === ' ' ) {
42- return this .$root .enquiry_data [this .field .field ] || ' '
62+ if (this .field . prefix ) {
63+ return ( this .$root .enquiry_data [ this . field . prefix ] || {}) [this .field .field ] || ' '
4364 } else {
44- return ( this .$root .enquiry_data [ this . prefix ] || {}) [this .field .field ] || ' '
65+ return this .$root .enquiry_data [this .field .field ] || ' '
4566 }
4667 }
4768 },
4869 methods: {
4970 changed : function (event ) {
50- if (this .prefix === ' ' ) {
51- this .$set (this .$root .enquiry_data , this .field .field , event .target .value )
71+ if (this .field .prefix ) {
72+ let obj = this .$root .enquiry_data [this .field .prefix ] || {}
73+ obj[this .field .field ] = this .field .type === ' checkbox' ? event .target .checked : event .target .value
74+ this .$set (this .$root .enquiry_data , this .field .prefix , obj)
75+ this .$root .enquiry_data = Object .assign ({}, this .$root .enquiry_data )
5276 } else {
53- var obj = this .$root .enquiry_data [this .prefix ] || {}
54- obj[this .field .field ] = event .target .value
55- this .$set (this .$root .enquiry_data , this .prefix , obj)
77+ this .$set (this .$root .enquiry_data , this .field .field , event .target .value )
5678 }
5779 }
5880 },
@@ -64,23 +86,46 @@ export default {
6486
6587$border-colour : #66afe9 ;
6688.tcs-field {
89+ & .required {
90+ .help-text {
91+ content : " Read this: " ;
92+ }
93+ }
94+
6795 padding : 8px 0 ;
6896 width : 100% ;
69- input , textarea {
97+ input , textarea , select {
7098 font-size : 16px ;
7199 box-sizing : border-box ;
72100 width : 100% ;
73- padding : 10 px 12px ;
101+ padding : 8 px 12px 10 px ;
74102 margin : 0 ;
75103 height : inherit ;
76104 border-radius : 5px ;
77105 border : 1px solid #aaa ;
78106 font-family : inherit ;
79107 outline : none ;
108+ background-color : white ;
80109 & :focus {
81110 border-color : $border-colour ;
82111 box-shadow : inset 0 1px 1px rgba (0 ,0 ,0 ,.075 ), 0 0 8px lighten ($border-colour , 20% );
83112 }
113+ & :required {
114+ border : 1px solid #888 ;
115+ }
116+ }
117+ label {
118+ display : block ;
119+ }
120+ input [type = " checkbox" ] {
121+ width : auto ;
122+ }
123+ .help-text {
124+ font-size : 14px ;
125+ color : #888 ;
126+ & .muted {
127+ display : none ;
128+ }
84129 }
85130}
86131 </style >
0 commit comments