1
1
<template >
2
- <f7-input v-if =" !config.item || !config.sendButton" class =" input-field" ref =" input" v-bind =" config" :style =" config.style"
3
- :value =" ((config.type && config.type.indexOf('date') === 0) || config.type === 'time') ? valueForDatepicker : value"
4
- :calendar-params =" calendarParams" :step =" config.step ? config.step : 'any'"
5
- @input =" $evt => updated($evt.target.value)" :change =" updated" @calendar:change =" updated" @texteditor:change =" updated" @colorpicker:change =" updated" >
6
- <template v-if =" context .component .slots && context .component .slots .default " >
7
- <generic-widget-component :context =" childContext(slotComponent)" v-for =" (slotComponent, idx) in context.component.slots.default" :key =" 'default-' + idx" />
8
- </template >
9
- </f7-input >
10
- <f7-row no-gap v-else class =" oh-input-with-send-button" :style =" config.style" >
11
- <f7-input class =" input-field col-80" ref =" input" v-bind =" config"
2
+ <f7-row no-gap v-if =" !config.item || !config.sendButton" class =" oh-input" :style =" config.style" >
3
+ <f7-input class =" input-field" ref =" input" v-bind =" config" :style =" {width: '100%', ...config.style}"
12
4
:value =" ((config.type && config.type.indexOf('date') === 0) || config.type === 'time') ? valueForDatepicker : value"
13
5
:calendar-params =" calendarParams" :step =" config.step ? config.step : 'any'"
6
+ @focus =" listenForEnterKey"
7
+ @blur =" stopListeningForEnterKey"
14
8
@input =" $evt => updated($evt.target.value)" :change =" updated" @calendar:change =" updated" @texteditor:change =" updated" @colorpicker:change =" updated" >
15
9
<template v-if =" context .component .slots && context .component .slots .default " >
16
10
<generic-widget-component :context =" childContext(slotComponent)" v-for =" (slotComponent, idx) in context.component.slots.default" :key =" 'default-' + idx" />
17
11
</template >
18
12
</f7-input >
13
+ <span v-if =" unit" class =" unit" >{{ unit }}</span >
14
+ </f7-row >
15
+ <f7-row no-gap v-else class =" oh-input" :style =" config.style" >
16
+ <f7-input class =" input-field" ref =" input" v-bind =" config"
17
+ :value =" ((config.type && config.type.indexOf('date') === 0) || config.type === 'time') ? valueForDatepicker : value"
18
+ :calendar-params =" calendarParams" :step =" config.step ? config.step : 'any'"
19
+ :style =" { width: '100%' }"
20
+ @focus =" listenForEnterKey"
21
+ @blur =" stopListeningForEnterKey"
22
+ @input =" $evt => updated($evt.target.value)" :change =" updated" @calendar:change =" updated" @texteditor:change =" updated" @colorpicker:change =" updated" >
23
+ <template v-if =" context .component .slots && context .component .slots .default " >
24
+ <generic-widget-component :context =" childContext(slotComponent)" v-for =" (slotComponent, idx) in context.component.slots.default" :key =" 'default-' + idx" />
25
+ </template >
26
+ </f7-input >
27
+ <span v-if =" unit" class =" unit" >{{ unit }}</span >
19
28
<f7-button class =" send-button col-10" v-if =" this.config.sendButton" @click.stop =" sendButtonClicked" v-bind =" config.sendButtonConfig || { iconMaterial: 'done', iconColor: 'gray' }" />
20
29
</f7-row >
21
30
</template >
22
31
23
32
<style lang="stylus">
24
- .oh-input-with-send-button
33
+ input [type = number ]
34
+ text-align right
35
+ .oh-input
36
+ flex-wrap nowrap !important
37
+ align-items center !important
38
+ .unit
39
+ margin-left 4px
25
40
.input-field
26
41
padding-left 8px
27
42
padding-right 8px
28
- --f7-input-font-size 1rem
29
43
.send-button
30
- --f7-button-padding-horizontal 0 px
44
+ --f7-button-padding-horizontal 0
31
45
</style >
32
46
33
47
<script >
@@ -59,17 +73,23 @@ export default {
59
73
}
60
74
} else if (this .config .variable && variableLocation[this .config .variable ] !== undefined ) {
61
75
return variableLocation[this .config .variable ]
62
- } else if (this .config . sendButton && this . pendingUpdate !== null ) {
76
+ } else if (this .pendingUpdate !== null ) {
63
77
return this .pendingUpdate
64
- } else if (this .config .item && this .context .store [this .config .item ].state !== ' NULL' && this .context .store [this .config .item ].state !== ' UNDEF' && this .context .store [this .config .item ].state !== ' Invalid Date' ) {
65
- if (this .config .useDisplayState ) {
66
- return this .context .store [this .config .item ].displayState || this .context .store [this .config .item ].state
67
- } else {
68
- return this .context .store [this .config .item ].state
78
+ } else if (this .config .item ) {
79
+ const item = this .context .store [this .config .item ]
80
+ if (item .state !== ' NULL' && item .state !== ' UNDEF' && item .state !== ' Invalid Date' ) {
81
+ let value = this .config .useDisplayState ? item .displayState || item .state : item .state
82
+ if (this .config .type === ' number' && this .unit ) {
83
+ value = value .split (' ' )[0 ]
84
+ }
85
+ return value
69
86
}
70
87
}
71
88
return this .config .defaultValue
72
89
},
90
+ unit () {
91
+ return this .config .type === ' number' && this .config .item && this .context .store [this .config .item ].unit
92
+ },
73
93
calendarParams () {
74
94
if (this .config .type !== ' datepicker' ) return null
75
95
let params = { dateFormat: { year: ' numeric' , month: ' numeric' , day: ' numeric' } }
@@ -121,9 +141,7 @@ export default {
121
141
} else if (this .config .type === ' datepicker' && Array .isArray (value) && this .valueForDatepicker [0 ].getTime () === value[0 ].getTime ()) {
122
142
return
123
143
}
124
- if (this .config .sendButton ) {
125
- this .$set (this , ' pendingUpdate' , value)
126
- }
144
+ this .$set (this , ' pendingUpdate' , value)
127
145
if (this .config .variable ) {
128
146
const variableScope = this .getVariableScope (this .context .ctxVars , this .context .varScope , this .config .variable )
129
147
const variableLocation = (variableScope) ? this .context .ctxVars [variableScope] : this .context .vars
@@ -133,13 +151,26 @@ export default {
133
151
this .$set (variableLocation, this .config .variable , value)
134
152
}
135
153
},
154
+ listenForEnterKey (evt ) {
155
+ evt .target .addEventListener (' keyup' , this .keyUp )
156
+ },
157
+ stopListeningForEnterKey (evt ) {
158
+ evt .target .removeEventListener (' keyup' , this .keyUp )
159
+ },
160
+ keyUp (evt ) {
161
+ if (evt .key === ' Enter' ) {
162
+ this .sendButtonClicked ()
163
+ }
164
+ },
136
165
sendButtonClicked () {
137
166
if (this .config .item && this .pendingUpdate ) {
138
167
let cmd = this .pendingUpdate
139
- if (this .config .type === ' datepicker' && Array .isArray (cmd)) {
168
+ if (this .unit ) {
169
+ cmd += ' ' + this .unit
170
+ } else if (this .config .type === ' datepicker' && Array .isArray (cmd)) {
140
171
cmd = dayjs (cmd[0 ]).format ()
172
+ if (cmd === ' Invalid Date' ) return
141
173
}
142
- if (cmd === ' Invalid Date' ) return
143
174
this .$store .dispatch (' sendCommand' , { itemName: this .config .item , cmd })
144
175
this .$set (this , ' pendingUpdate' , null )
145
176
}
0 commit comments