Jigar Prajapati
Jigar Prajapati

Reputation: 13

How to set character limit in react-native pell rich editor?

I want to set max character length 3000 in richeditor. I am using react-native-pell-rich-editor. When a user inserts more then 3000 character then all extra characters should automatically remove. I am receiving html content.

So any solutions for this problem?

Here is my code :

<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}
/>

Upvotes: 1

Views: 1611

Answers (1)

Md. Robi Ullah
Md. Robi Ullah

Reputation: 2162

My solution:

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;
        }
    }
}

Upvotes: 2

Related Questions