微信小程序表單組件 form

2022-05-11 16:07 更新

微信小程序form

基礎(chǔ)庫 1.0.0 開始支持,低版本需做兼容處理。

表單。將組件內(nèi)的用戶輸入的switch input checkbox slider radio picker 提交。

當(dāng)點(diǎn)擊 form 表單中 form-type 為 submit 的 button 組件時(shí),會將表單組件中的 value 值進(jìn)行提交,需要在表單組件中加上 name 來作為 key。

屬性 類型 默認(rèn)值 必填 說明 最低版本
report-submit boolean false 是否返回 formId 用于發(fā)送模板消息 1.0.0
report-submit-timeout number 0 等待一段時(shí)間(毫秒數(shù))以確認(rèn) formId 是否生效。如果未指定這個(gè)參數(shù),formId 有很小的概率是無效的(如遇到網(wǎng)絡(luò)失敗的情況)。指定這個(gè)參數(shù)將可以檢測 formId 是否有效,以這個(gè)參數(shù)的時(shí)間作為這項(xiàng)檢測的超時(shí)時(shí)間。如果失敗,將返回 requestFormId:fail 開頭的 formId 2.6.2
bindsubmit eventhandle 攜帶 form 中的數(shù)據(jù)觸發(fā) submit 事件,event.detail = {value : {'name': 'value'} , formId: ''} 1.0.0
bindreset eventhandle 表單重置時(shí)會觸發(fā) reset 事件 1.0.0

示例代碼:

<form bindsubmit="formSubmit" bindreset="formReset">
    <view class="section section_gap">
        <view class="section__title">switch</view>
        <switch name="switch"/>
    </view>
    <view class="section section_gap">
        <view class="section__title">slider</view>
        <slider name="slider" show-value ></slider>
    </view>

    <view class="section">
        <view class="section__title">input</view>
        <input name="input" placeholder="please input here" />
    </view>
    <view class="section section_gap">
        <view class="section__title">radio</view>
        <radio-group name="radio-group">
            <label><radio value="radio1"/>radio1</label>
            <label><radio value="radio2"/>radio2</label>
        </radio-group>
    </view>
    <view class="section section_gap">
        <view class="section__title">checkbox</view>
        <checkbox-group name="checkbox">
            <label><checkbox value="checkbox1"/>checkbox1</label>
            <label><checkbox value="checkbox2"/>checkbox2</label>
        </checkbox-group>
    </view>
    <view class="btn-area">
        <button formType="submit">Submit</button>
        <button formType="reset">Reset</button>
    </view>
</form>
Page({
  formSubmit: function(e) {
    console.log('form發(fā)生了submit事件,攜帶數(shù)據(jù)為:', e.detail.value)
  },
  formReset: function() {
    console.log('form發(fā)生了reset事件')
  }
})

form


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號