1
0
mirror of https://gitee.com/vant-contrib/vant-weapp.git synced 2025-04-06 03:58:05 +08:00

[bugfix] Field: with form component ()

This commit is contained in:
neverland 2018-08-21 14:35:40 +08:00 committed by GitHub
parent 5e65176fb7
commit ac358578c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 18 deletions
packages/field

@ -43,10 +43,7 @@ Component({
}, },
value: { value: {
type: null, type: null,
value: '', value: ''
observer(currentValue) {
this.setData({ currentValue });
}
}, },
type: { type: {
type: String, type: String,
@ -60,14 +57,7 @@ Component({
data: { data: {
focused: false, focused: false,
showClear: false, showClear: false
currentValue: ''
},
attached() {
this.setData({
currentValue: this.data.value
});
}, },
methods: { methods: {
@ -76,7 +66,7 @@ Component({
this.triggerEvent('input', value); this.triggerEvent('input', value);
this.triggerEvent('change', value); this.triggerEvent('change', value);
this.setData({ this.setData({
currentValue: value, value,
showClear: this.getShowClear({ value }) showClear: this.getShowClear({ value })
}); });
}, },
@ -105,7 +95,7 @@ Component({
getShowClear(options) { getShowClear(options) {
const { const {
focused = this.data.focused, focused = this.data.focused,
value = this.data.currentValue value = this.data.value
} = options; } = options;
return this.data.clearable && focused && value !== '' && !this.data.readonly; return this.data.clearable && focused && value !== '' && !this.data.readonly;
@ -113,7 +103,7 @@ Component({
onClear() { onClear() {
this.setData({ this.setData({
currentValue: '', value: '',
showClear: this.getShowClear({ value: '' }) showClear: this.getShowClear({ value: '' })
}); });
this.triggerEvent('input', ''); this.triggerEvent('input', '');
@ -121,7 +111,7 @@ Component({
}, },
onConfirm() { onConfirm() {
this.triggerEvent('confirm', this.data.currentValue); this.triggerEvent('confirm', this.data.value);
} }
} }
}); });

@ -15,7 +15,7 @@
wx:if="{{ type === 'textarea' }}" wx:if="{{ type === 'textarea' }}"
class="input-class van-field__control van-field__textarea {{ inputAlign ? 'van-field--' + inputAlign : '' }} {{ error ? 'van-field--error' : '' }} {{ disabled ? 'van-field__control--disabled' : '' }}" class="input-class van-field__control van-field__textarea {{ inputAlign ? 'van-field--' + inputAlign : '' }} {{ error ? 'van-field--error' : '' }} {{ disabled ? 'van-field__control--disabled' : '' }}"
focus="{{ focus }}" focus="{{ focus }}"
value="{{ currentValue }}" value="{{ value }}"
disabled="{{ disabled }}" disabled="{{ disabled }}"
readonly="{{ readonly }}" readonly="{{ readonly }}"
maxlength="{{ maxlength }}" maxlength="{{ maxlength }}"
@ -33,7 +33,7 @@
class="input-class van-field__control {{ inputAlign ? 'van-field--' + inputAlign : '' }} {{ error ? 'van-field--error' : '' }} {{ disabled ? 'van-field__control--disabled' : '' }}" class="input-class van-field__control {{ inputAlign ? 'van-field--' + inputAlign : '' }} {{ error ? 'van-field--error' : '' }} {{ disabled ? 'van-field__control--disabled' : '' }}"
type="{{ type }}" type="{{ type }}"
focus="{{ focus }}" focus="{{ focus }}"
value="{{ currentValue }}" value="{{ value }}"
disabled="{{ disabled }}" disabled="{{ disabled }}"
readonly="{{ readonly }}" readonly="{{ readonly }}"
maxlength="{{ maxlength }}" maxlength="{{ maxlength }}"