首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在react-native pell富编辑器中设置字符限制?

如何在react-native pell富编辑器中设置字符限制?
EN

Stack Overflow用户
提问于 2021-07-22 20:25:33
回答 1查看 136关注 0票数 1

我想在richeditor中设置最大字符长度3000。我使用的是react-native-pell-rich-editor。当用户插入超过3000个字符时,所有额外的字符都应该自动删除。我正在接收html内容。

那么这个问题有什么解决方案吗?

下面是我的代码:

代码语言:javascript
复制
<RichEditor
    disabled={false}
    initialContentHTML={summary}
    style={{
      height: "100%",
      backgroundColor: "white",
      flex: 1,
      paddingTop: 1,
      paddingBottom: 5,
      justifyContent: "center",
      minHeight: "100%",
      minWidth: "100%",
      width: "100%",
    }}
    showsVerticalScrollIndicator={false}
    scrollEnabled={false}
    ref={editor}
    placeholder={"Write summary (Max 3000 char)"}
    onChange={changeHTML}
/>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-30 15:24:34

我的解决方案是:

代码语言:javascript
复制
changeHTML= (val) => {
    if(val != this.prevDescVal){
        let rawVal = val;
        if(val.replace(/<[^>]*>/g, '').length > 1500 ){
            this.richtext.current?.setContentHTML('');
            this.richtext.current?.insertHTML(this.prevDescVal);
            this.toast.show({
                text: "Maximum limit 1500",
                type: "failed",
            });
        }else{
            this.prevDescVal = rawVal;
        }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68484823

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档