[improvement] SwitchCell: support form-filed (#479)

This commit is contained in:
neverland 2018-08-29 16:45:28 +08:00 committed by GitHub
parent 309cf21075
commit c8836b8d6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 2 deletions

View File

@ -1,20 +1,31 @@
Component({ Component({
behaviors: ['wx://form-field'],
options: { options: {
addGlobalClass: true addGlobalClass: true
}, },
properties: { properties: {
title: String, title: String,
checked: Boolean,
border: Boolean, border: Boolean,
loading: Boolean, loading: Boolean,
disabled: Boolean, disabled: Boolean,
checked: {
type: Boolean,
observer(value) {
this.setData({ value });
}
},
size: { size: {
type: String, type: String,
value: '26px' value: '26px'
} }
}, },
attached() {
this.setData({ value: this.data.checked });
},
methods: { methods: {
onChange(event) { onChange(event) {
this.triggerEvent('change', event.detail); this.triggerEvent('change', event.detail);

View File

@ -61,6 +61,7 @@ Page({
| 参数 | 说明 | 类型 | 默认值 | | 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------| |-----------|-----------|-----------|-------------|
| name | 在表单内提交时的标识符 | `String` | - |
| checked | 开关状态 | `Boolean` | - | | checked | 开关状态 | `Boolean` | - |
| title | 左侧标题 | `String` | `''` | | title | 左侧标题 | `String` | `''` |
| loading | 是否为加载状态 | `Boolean` | `false` | | loading | 是否为加载状态 | `Boolean` | `false` |

View File

@ -1,20 +1,31 @@
Component({ Component({
behaviors: ['wx://form-field'],
options: { options: {
addGlobalClass: true addGlobalClass: true
}, },
properties: { properties: {
title: String, title: String,
checked: Boolean,
border: Boolean, border: Boolean,
loading: Boolean, loading: Boolean,
disabled: Boolean, disabled: Boolean,
checked: {
type: Boolean,
observer(value) {
this.setData({ value });
}
},
size: { size: {
type: String, type: String,
value: '26px' value: '26px'
} }
}, },
attached() {
this.setData({ value: this.data.checked });
},
methods: { methods: {
onChange(event) { onChange(event) {
this.triggerEvent('change', event.detail); this.triggerEvent('change', event.detail);