我想在richeditor中设置最大字符长度3000。我使用的是react-native-pell-rich-editor。当用户插入超过3000个字符时,所有额外的字符都应该自动删除。我正在接收html内容。
那么这个问题有什么解决方案吗?
下面是我的代码:
<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}
/>发布于 2021-09-30 15:24:34
我的解决方案是:
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;
}
}
}https://stackoverflow.com/questions/68484823
复制相似问题