Skip to content

Commit

Permalink
Merge pull request #1569 from djtoohey/inputRichTextFSC-remove-html-f…
Browse files Browse the repository at this point in the history
…rom-character-count

inputRichTextFSC - remove html from character count in
  • Loading branch information
alexed1 committed Sep 21, 2024
2 parents c2920ca + 8075f92 commit ec7bbd5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 06/25/21 Eric Smith Added a Required attribute and increased the bottom margin to better match standard components
// 07/02/21 Eric Smith Added a Required * to the Input Label if Required is True
// 04/04/23 Clifford Beul Added disabled categories and optional overwrite of formats
// 01/08/24 Declan Toohey Modified character count calculation to not include HTML characters in character count

import { LightningElement, api, track } from 'lwc';

Expand All @@ -18,6 +19,7 @@ export default class inputRichTextFSC_LWC extends LightningElement {
@api required = false;
@api disabledCategories = '';
@api enabledFormats;
@api excludeHTMLCharacterCount = false;
formats = ['font', 'size', 'bold', 'italic', 'underline',
'strike', 'list', 'indent', 'align', 'link',
Expand Down Expand Up @@ -193,7 +195,13 @@ export default class inputRichTextFSC_LWC extends LightningElement {
this.isValidCheck = true;
this.richText = event.target.value;
}

this.characterCount = this.richText.length;
if (this.excludeHTMLCharacterCount) {
//Regex <[^>]*> removes any HTML from the word count
this.characterCount = this.richText.replace(/<[^>]*>/ig, "").length;
}

if(this.characterCap && this.characterCount > this.characterLimit){
this.isValidCheck = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<property label="Warning Only" name="warnOnly" type="Boolean" role="inputOnly" description="Set to True if you want disallowed Symbols or Words to only alert and not block next/finish. Default is false."/>
<property label="Character Limit" name="characterLimit" type="Integer" role="inputOnly" description="If set, then the character count will be limited to this quantity."/>
<property label="Required?" name="required" type="Boolean" role="inputOnly" default="false" description="Set to True if you want to require an entry for this input."/>
<property label="Exclude HTML in character count?" name="excludeHTMLCharacterCount" type="Boolean" role="inputOnly" default="false" description="Set to True if you want to exclude HTML characters in the character count."/>
</targetConfig>
</targetConfigs>
</LightningComponentBundle>

0 comments on commit ec7bbd5

Please sign in to comment.