当前位置:网站首页>Applet password input box

Applet password input box

2022-06-25 19:33:00 Bin daotianxia

Applet password input box .

The initial state is input Can't click .

Click on input Eject keyboard later . After all the input boxes are entered, you can click Submit .

 

Specific code :

<view class="Toptitle"> Please set the payment password and keep it properly </view>
<form bindsubmit="formSubmit">
  <view class='content'>
    <block wx:for="{
   {Length}}" wx:key="item">
      <input class='iptbox' value="{
   {Value.length>=index+1?Value[index]:''}}" disabled password='{
   {ispassword}}' catchtap='Tap'></input>
    </block>
  </view>
  <input name="password" password="{
   {true}}" class='ipt' maxlength="{
   {Length}}" focus="{
   {isFocus}}" bindinput="Focus"></input>
  <view>
    <button class="btn-area" type='primary' disabled='{
   {disabled}}' formType="primary"> next step </button>
  </view>
</form>

CSS It's very simple :

.Toptitle{
  text-align: center;
  margin: 60rpx auto 46rpx;
  font-size: 26rpx;
}
.content{
  width: 660rpx;
  padding:0 45rpx;
  display: flex;
  justify-content: space-around;
  align-items: center;
  margin-top: 100rpx;
}
.iptbox{
  width: 110rpx;
  height: 96rpx;
  border:1rpx solid #ddd;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
}
.ipt{
  width: 0;
  height: 0;
}
.btn-area{
  width: 80%;
  margin-top: 60rpx;
}

The key is JS. Focus popup IME , After losing focus, go to the next .


Page({
  data: {
    Length: 6,        // Number of input fields 
    isFocus: true,    // focusing 
    Value: "",        // Input content 
    ispassword: true, // Whether the ciphertext is displayed  true For the cipher , false In plain text .
    disabled:true,
  },
  Focus(e) {
    var that = this;
    console.log(e.detail.value);
    var inputValue = e.detail.value;
    var ilen = inputValue.length;
    if(ilen == 6){
      that.setData({
        disabled: false,
      })
    }else{
      that.setData({
        disabled: true,
      })
    }
    that.setData({
      Value: inputValue,
    })
  },
  Tap() {
    var that = this;
    that.setData({
      isFocus: true,
    })
  },
  formSubmit(e) {
    console.log(e.detail.value.password);
  },

  onLoad: function (options) {
  
  },
  onShow: function () {
  
  },
})

 

原网站

版权声明
本文为[Bin daotianxia]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202190518211127.html