HarmonyOS RichEditor实现超过文字字数删除功能,发现删除功能失效

RichEditor无法实现输入文字超过限制功能。

HarmonyOS
2024-10-17 11:48:12
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple
// 输入框文字校验  
inputNumCheck(){  
  this.controllerRich.getSpans({  
    start: this.start,  
    end: this.end}).forEach(item => {  
    if (typeof (item as RichEditorImageSpanResult)['imageStyle'] !== 'undefined') {  
      this.inputNum++  
    } else {  
      this.inputNum = (item as RichEditorTextSpanResult).value.length;  
    }  
  })  
}  
build() {  
  Column() {  
    Row(){  
      // 输入框  
      RichEditor({ controller: this.controllerRich})  
        .height($r('app.integer.chat_with_expression_chat_input_height'))  
        .layoutWeight(LAYOUT_WEIGHT)  
        .borderRadius($r('app.integer.chat_with_expression_chat_border_radius'))  
        .backgroundColor($r('app.string.chat_with_expression_input_background'))  
        .margin({ top: $r('app.integer.chat_with_expression_express_margin_top') ,left:14})  
        .key(this.focusKey)  
        .id(this.focusKey)  
        .placeholder('平台提倡文明用语,请温柔发言哦~',{font:{size:12},fontColor:'#999999'})  
        .defaultFocus(true)  
        .aboutToIMEInput((value: RichEditorInsertValue)=>{  
          if (this.inputNum >= 50) {  
            // 输入字符数超过50个 就禁止输入  
            try {  
              promptAction.showToast({  
                message: '最多只能输入50个汉字哦',  
                duration: 2000  
              });  
            } catch (error) {  
              let message = (error as BusinessError).message  
              let code = (error as BusinessError).code  
              console.error(`showToast args error code is ${code}, message is ${message}`);  
            };  
            return false  
          } else {  
            this.inputNumCheck()  
          }  
          return true  
        })
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
分享
微博
QQ
微信
回复
2024-10-17 15:13:27
相关问题
Text如何实现删除线的功能
2229浏览 • 1回复 待解决
【JS】如何实现左滑删除功能
4294浏览 • 1回复 待解决
HarmonyOS元服务添加、删除功能
1865浏览 • 1回复 待解决
RichEditor添加、删除、重载图片
1812浏览 • 1回复 待解决
如何实现ArrayList的删除、去重等功能
1249浏览 • 1回复 待解决
侧滑删除功能的列表有哪些?
1560浏览 • 1回复 待解决
HarmonyOS Web 图片上传功能失效
845浏览 • 1回复 待解决