[new feature] Field: 增加 value 传入支持 (#60)

* field 支持 value 传入

* textarea 清除输入示例
This commit is contained in:
Yao 2017-11-17 21:13:35 +08:00 committed by GitHub
parent 12ace17fdc
commit 9c05bd2d58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 2 deletions

View File

@ -2,6 +2,8 @@ var Zan = require('../../dist/index');
Page(Object.assign({}, Zan.Field, { Page(Object.assign({}, Zan.Field, {
data: { data: {
value: 'test',
textareaValue: 'test textarea',
area: ['省份', '北京市', '天津市', '河北省', '山西省', '内蒙古自治区', '辽宁省', '吉林省', '黑龙江省', '上海市', '江苏省', '浙江省', '安徽省', '福建省', '江西省', '山东省', '河南省', '湖北省', '湖南省', '广东省', '广西壮族自治区', '海南省', '重庆市', '四川省', '贵州省', '云南省', '西藏自治区', '陕西省', '甘肃省', '青海省', '宁夏回族自治区', '新疆维吾尔自治区', '台湾省', '香港特别行政区', '澳门特别行政区'], area: ['省份', '北京市', '天津市', '河北省', '山西省', '内蒙古自治区', '辽宁省', '吉林省', '黑龙江省', '上海市', '江苏省', '浙江省', '安徽省', '福建省', '江西省', '山东省', '河南省', '湖北省', '湖南省', '广东省', '广西壮族自治区', '海南省', '重庆市', '四川省', '贵州省', '云南省', '西藏自治区', '陕西省', '甘肃省', '青海省', '宁夏回族自治区', '新疆维吾尔自治区', '台湾省', '香港特别行政区', '澳门特别行政区'],
areaIndex: 0 areaIndex: 0
}, },
@ -16,5 +18,17 @@ Page(Object.assign({}, Zan.Field, {
const { componentId, detail } = e; const { componentId, detail } = e;
console.log('[zan:field:change]', componentId, detail); console.log('[zan:field:change]', componentId, detail);
},
clearInput() {
this.setData({
value: ''
});
},
clearTextarea() {
this.setData({
textareaValue: ''
});
} }
})); }));

View File

@ -5,14 +5,22 @@
<view class="zan-panel-title">基础用法</view> <view class="zan-panel-title">基础用法</view>
<view class="zan-panel"> <view class="zan-panel">
<template is="zan-field" data="{{ title: '收货人', type: 'input', placeholder: '名字' }}"></template> <template is="zan-field" data="{{ title: '收货人', type: 'input', placeholder: '名字', value: value }}"></template>
<template is="zan-field" data="{{ title: '联系电话', type: 'input', inputType: 'number', placeholder: '请输入手机号', error: true }}"></template> <template is="zan-field" data="{{ title: '联系电话', type: 'input', inputType: 'number', placeholder: '请输入手机号', error: true }}"></template>
<template is="zan-field" data="{{ title: '详细地址', type: 'textarea', placeholder: '请输入详细地址' }}"></template> <template is="zan-field" data="{{ title: '详细地址', type: 'textarea', placeholder: '请输入详细地址' }}"></template>
</view> </view>
<view class="zan-btns">
<button class="zan-btn zan-btn--primary" bindtap="clearInput">清除输入</button>
</view>
<view class="zan-panel-title">无标题输入框</view> <view class="zan-panel-title">无标题输入框</view>
<view class="zan-panel"> <view class="zan-panel">
<template is="zan-field" data="{{ type: 'input', placeholder: '请输入收货人姓名' }}"></template> <template is="zan-field" data="{{ type: 'input', placeholder: '请输入收货人姓名', value: textareaValue }}"></template>
</view>
<view class="zan-btns">
<button class="zan-btn zan-btn--primary" bindtap="clearTextarea">清除输入</button>
</view> </view>
<view class="zan-panel-title field__title--radius">圆角输入框</view> <view class="zan-panel-title field__title--radius">圆角输入框</view>

View File

@ -6,6 +6,7 @@
<textarea <textarea
wx:if="{{ type === 'textarea' }}" wx:if="{{ type === 'textarea' }}"
auto-height auto-height
value="{{ value }}"
placeholder="{{ placeholder }}" placeholder="{{ placeholder }}"
class="zan-field__input zan-cell__bd {{ right ? 'zan-field__input--right' : '' }}" class="zan-field__input zan-cell__bd {{ right ? 'zan-field__input--right' : '' }}"
placeholder-class="zan-field__placeholder" placeholder-class="zan-field__placeholder"
@ -14,6 +15,7 @@
<input <input
wx:else wx:else
type="{{ inputType || 'text' }}" type="{{ inputType || 'text' }}"
value="{{ value }}"
placeholder="{{ placeholder }}" placeholder="{{ placeholder }}"
class="zan-field__input zan-cell__bd {{ right ? 'zan-field__input--right' : '' }}" class="zan-field__input zan-cell__bd {{ right ? 'zan-field__input--right' : '' }}"
placeholder-class="zan-field__placeholder" placeholder-class="zan-field__placeholder"