Skip to content

Commit e4572b0

Browse files
pdanpdanrstoenescu
authored andcommitted
close quasarframework#1883 - refactor QDatetime and QColor model (quasarframework#1885)
- QDatetime on iOS does not have unselected value, so we're setting it to default - QColor cannot have unselected value, so we're setting it to default close quasarframework#1883
1 parent b51af61 commit e4572b0

File tree

4 files changed

+37
-37
lines changed

4 files changed

+37
-37
lines changed

dev/components/form/all.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,11 @@
232232
<q-select :dark="dark" color="black" :error="error" :warning="warning" :disable="disable" :readonly="readonly" multiple chips inverted :clearable="clearable" class="q-ma-sm" @focus="onFocus" @blur="onBlur" @change="val => { options = val; onChange(val) }" @input="onInput" @clear="onClear" :value="options" :options="countries" float-label="Select multiple - chips (onChange)" filter />
233233

234234
<p class="q-subtitle">Color selected: {{ JSON.stringify(color) }}</p>
235-
<q-color :dark="dark" :error="error" :warning="warning" :disable="disable" :readonly="readonly" :clearable="clearable" class="q-ma-sm" @focus="onFocus" @blur="onBlur" @change="onChange" @input="onInput" @clear="onClear" v-model="color" placeholder="Color (RGBA)" format-model="rgba" :after="[ { icon: 'colorize', handler () { color = defaultColor } }]" />
235+
<q-color :dark="dark" :error="error" :warning="warning" :disable="disable" :readonly="readonly" :clearable="clearable" class="q-ma-sm" @focus="onFocus" @blur="onBlur" @change="onChange" @input="onInput" @clear="onClear" v-model="color" placeholder="Color (RGBA)" format-model="rgba" :after="[ { icon: 'colorize', handler () { color = '#f00' } }]" />
236236
<q-color :dark="dark" :error="error" :warning="warning" :disable="disable" :readonly="readonly" :clearable="clearable" class="q-ma-sm" @focus="onFocus" @blur="onBlur" @change="onChange" @input="onInput" @clear="onClear" v-model="color" float-label="Color (RGBA)" format-model="rgba" />
237237
<q-color :dark="dark" color="primary" :error="error" :warning="warning" :disable="disable" :readonly="readonly" inverted :clearable="clearable" class="q-ma-sm" @focus="onFocus" @blur="onBlur" @change="val => { color = val; onChange(val) }" @input="onInput" @clear="onClear" :value="color" float-label="Color (onChange)" />
238238
<q-color :dark="dark" :error="error" :warning="warning" :disable="disable" :readonly="readonly" :clearable="clearable" class="q-ma-sm" @focus="onFocus" @blur="onBlur" @change="onChange" @input="onInput" @clear="onClear" v-model="color" :default-value="defaultColor" :float-label="`Color (default ${defaultColor})`" />
239-
<q-color :dark="dark" color="primary" :error="error" :warning="warning" :disable="disable" :readonly="readonly" inverted :clearable="clearable" class="q-ma-sm" @focus="onFocus" @blur="onBlur" @change="val => { color = val; onChange(val) }" @input="onInput" @clear="onClear" :value="color" :default-value="defaultColor" :float-label="`Color (default ${defaultColor}, onChange)`" :after="[ { icon: 'colorize', handler () { color = defaultColor } }]" />
239+
<q-color :dark="dark" color="primary" :error="error" :warning="warning" :disable="disable" :readonly="readonly" inverted :clearable="clearable" class="q-ma-sm" @focus="onFocus" @blur="onBlur" @change="val => { color = val; onChange(val) }" @input="onInput" @clear="onClear" :value="color" :default-value="defaultColor" :float-label="`Color (default ${defaultColor}, onChange)`" :after="[ { icon: 'colorize', handler () { color = '#f00' } }]" />
240240

241241
<p class="q-subtitle">Color selected: {{ JSON.stringify(colorP) }}</p>
242242
<div class="row gutter-sm">
@@ -259,7 +259,7 @@
259259
</div>
260260

261261
<p class="q-subtitle">Date selected: {{ JSON.stringify(date) }}</p>
262-
<q-datetime :dark="dark" :error="error" :warning="warning" :disable="disable" :readonly="readonly" type="date" formatModel="date" :clearable="clearable" class="q-ma-sm" @focus="onFocus" @blur="onBlur" @change="onChange" @input="onInput" @clear="onClear" v-model="date" placeholder="Date" :after="[ { icon: 'today', handler () { date = new Date() } }]" />
262+
<q-datetime :dark="dark" :error="error" :warning="warning" :disable="disable" :readonly="readonly" type="date" formatModel="date" :clearable="clearable" class="q-ma-sm" @focus="onFocus" @blur="onBlur" @change="onChange" @input="onInput" @clear="onClear" v-model="date" placeholder="Date" :after="[ { icon: 'today', handler () { date = new Date('2018-10-21') } }]" />
263263
<q-datetime :dark="dark" :error="error" :warning="warning" :disable="disable" :readonly="readonly" type="date" formatModel="date" :clearable="clearable" class="q-ma-sm" @focus="onFocus" @blur="onBlur" @change="onChange" @input="onInput" @clear="onClear" v-model="date" float-label="Date" />
264264
<q-datetime :dark="dark" color="primary" :error="error" :warning="warning" :disable="disable" :readonly="readonly" type="date" formatModel="date" inverted :clearable="clearable" class="q-ma-sm" @focus="onFocus" @blur="onBlur" @change="val => { date = val; onChange(val) }" @input="onInput" @clear="onClear" :value="date" float-label="Date (onChange)" />
265265
<q-datetime :dark="dark" :error="error" :warning="warning" :disable="disable" :readonly="readonly" type="date" formatModel="date" :clearable="clearable" class="q-ma-sm" @focus="onFocus" @blur="onBlur" @change="onChange" @input="onInput" @clear="onClear" v-model="date" :default-value="defaultDate" :float-label="`Date (default ${defaultDate})`" />

src/components/color/QColor.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default {
3434
},
3535
defaultValue: {
3636
type: [String, Object],
37-
default: null
37+
default: '#000'
3838
},
3939
formatModel: {
4040
type: String,
@@ -48,7 +48,7 @@ export default {
4848
},
4949
watch: {
5050
value (v) {
51-
if (!this.disable && this.$refs.popup && this.$refs.popup.showing) {
51+
if (!this.disable && this.isPopover) {
5252
this.model = clone(v)
5353
}
5454
}
@@ -76,7 +76,7 @@ export default {
7676
return ''
7777
},
7878
modalBtnColor () {
79-
return this.$q.theme === 'mat'
79+
return __THEME__ === 'mat'
8080
? this.color
8181
: (this.dark ? 'light' : 'dark')
8282
}
@@ -87,18 +87,11 @@ export default {
8787
},
8888
show () {
8989
if (!this.disable) {
90-
const val = this.value || this.defaultValue
91-
if (this.focused) {
92-
this.model = clone(val)
93-
}
94-
else {
95-
this.__setModel(val)
96-
}
90+
this.__setModel(this.value || this.defaultValue)
9791
return this.$refs.popup.show()
9892
}
9993
},
10094
hide () {
101-
this.focused = false
10295
return this.$refs.popup.hide()
10396
},
10497

@@ -118,7 +111,7 @@ export default {
118111
if (this.disable || this.focused) {
119112
return
120113
}
121-
this.__setModel(this.value || this.defaultValue)
114+
this.model = clone(this.value || this.defaultValue)
122115
this.focused = true
123116
this.$emit('focus')
124117
},
@@ -136,15 +129,15 @@ export default {
136129
}, 1)
137130
},
138131
__onHide (forceUpdate) {
132+
this.focused && this.$emit('blur')
139133
this.focused = false
140-
this.$emit('blur')
141-
if (forceUpdate || (this.isPopover && this.$refs.popup.showing)) {
134+
if (forceUpdate || this.isPopover) {
142135
this.__update(forceUpdate)
143136
}
144137
},
145138
__setModel (val, forceUpdate) {
146139
this.model = clone(val)
147-
if (forceUpdate || (this.isPopover && this.$refs.popup.showing)) {
140+
if (forceUpdate || this.isPopover) {
148141
this.__update(forceUpdate)
149142
}
150143
},
@@ -233,6 +226,7 @@ export default {
233226
error: this.error,
234227
warning: this.warning,
235228
disable: this.disable,
229+
readonly: this.readonly,
236230
inverted: this.inverted,
237231
invertedLight: this.invertedLight,
238232
dark: this.dark,

src/components/datetime/QDatetime.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { QInputFrame } from '../input-frame'
66
import { QPopover } from '../popover'
77
import QDatetimePicker from './QDatetimePicker'
88
import { QBtn } from '../btn'
9-
import { clone, formatDate, isSameDate, isValid } from '../../utils/date'
9+
import { clone, formatDate, isSameDate, isValid, startOfDate } from '../../utils/date'
1010
import { QModal } from '../modal'
1111
import { getEventKey, stopAndPrevent } from '../../utils/event'
1212

@@ -31,7 +31,7 @@ export default {
3131
),
3232
watch: {
3333
value (v) {
34-
if (!this.disable && this.$refs.popup && this.$refs.popup.showing) {
34+
if (!this.disable && this.isPopover) {
3535
this.model = clone(v)
3636
}
3737
}
@@ -41,7 +41,7 @@ export default {
4141
transition: __THEME__ === 'ios' ? 'q-modal-bottom' : 'q-modal'
4242
}
4343
data.focused = false
44-
data.model = clone(isValid(this.value) ? this.value : this.defaultValue)
44+
data.model = clone(this.computedValue)
4545
return data
4646
},
4747
computed: {
@@ -70,8 +70,17 @@ export default {
7070

7171
return formatDate(this.value, format, /* for reactiveness */ this.$q.i18n.date)
7272
},
73+
computedValue () {
74+
if (isValid(this.value)) {
75+
return this.value
76+
}
77+
if (__THEME__ === 'ios') {
78+
return this.defaultValue || startOfDate(new Date(), 'day')
79+
}
80+
return this.defaultValue
81+
},
7382
modalBtnColor () {
74-
return this.$q.theme === 'mat'
83+
return __THEME__ === 'mat'
7584
? this.color
7685
: (this.dark ? 'light' : 'dark')
7786
}
@@ -82,18 +91,11 @@ export default {
8291
},
8392
show () {
8493
if (!this.disable) {
85-
const val = isValid(this.value) ? this.value : this.defaultValue
86-
if (this.focused) {
87-
this.model = clone(val)
88-
}
89-
else {
90-
this.__setModel(val)
91-
}
94+
this.__setModel(this.computedValue)
9295
return this.$refs.popup.show()
9396
}
9497
},
9598
hide () {
96-
this.focused = false
9799
return this.$refs.popup.hide()
98100
},
99101

@@ -122,7 +124,7 @@ export default {
122124
target.setView()
123125
}
124126
}
125-
this.__setModel(isValid(this.value) ? this.value : this.defaultValue)
127+
this.model = clone(this.computedValue)
126128
this.focused = true
127129
this.$emit('focus')
128130
},
@@ -140,15 +142,15 @@ export default {
140142
}, 1)
141143
},
142144
__onHide (forceUpdate) {
145+
this.focused && this.$emit('blur')
143146
this.focused = false
144-
this.$emit('blur')
145-
if (forceUpdate || (this.isPopover && this.$refs.popup.showing)) {
147+
if (forceUpdate || this.isPopover) {
146148
this.__update(forceUpdate)
147149
}
148150
},
149151
__setModel (val, forceUpdate) {
150152
this.model = clone(val)
151-
if (forceUpdate || (this.isPopover && this.$refs.popup.showing)) {
153+
if (forceUpdate || this.isPopover) {
152154
this.__update(forceUpdate)
153155
}
154156
},
@@ -230,7 +232,8 @@ export default {
230232
color: this.modalBtnColor,
231233
flat: true,
232234
label: this.okLabel || this.$q.i18n.label.set,
233-
noRipple: true
235+
noRipple: true,
236+
disable: !this.model
234237
},
235238
on: {
236239
click: () => {

src/components/datetime/QDatetimePicker.mat.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
:key="`md${monthDay}`"
143143
class="row items-center content-center justify-center cursor-pointer"
144144
:class="[color && monthDay === day ? `text-${color}` : null, {
145-
'q-datetime-day-active': monthDay === day,
145+
'q-datetime-day-active': isValid && monthDay === day,
146146
'q-datetime-day-today': monthDay === today,
147147
'disabled': !editable
148148
}]"
@@ -238,7 +238,7 @@
238238
import { height, width, offset, cssTransform } from '../../utils/dom'
239239
import { position, stopAndPrevent } from '../../utils/event'
240240
import { QBtn } from '../btn'
241-
import { isSameDate, adjustDate } from '../../utils/date'
241+
import { isSameDate, isValid, adjustDate } from '../../utils/date'
242242
import DateMixin from './datetime-mixin'
243243
import ParentFieldMixin from '../../mixins/parent-field'
244244
import Ripple from '../../directives/ripple'
@@ -379,6 +379,9 @@ export default {
379379
380380
return cssTransform(`rotate(${degrees}deg)`)
381381
},
382+
isValid () {
383+
return isValid(this.value)
384+
},
382385
today () {
383386
const today = new Date()
384387
return isSameDate(today, this.model, 'month')

0 commit comments

Comments
 (0)