Skip to content

Commit 6fb53b7

Browse files
authored
Merge pull request #1597 from JeroenSfdc/inputRichTextFSC-Reactivity
Input rich text fsc reactivity
2 parents 482da17 + f1be1b8 commit 6fb53b7

File tree

2 files changed

+38
-27
lines changed

2 files changed

+38
-27
lines changed

flow_screen_components/richTextInputFSC/force-app/main/default/lwc/inputRichTextFSC/inputRichTextFSC.js

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,25 @@
22
// 07/02/21 Eric Smith Added a Required * to the Input Label if Required is True
33
// 04/04/23 Clifford Beul Added disabled categories and optional overwrite of formats
44
// 01/08/24 Declan Toohey Modified character count calculation to not include HTML characters in character count
5+
// 14/10/24 Jeroen Burgers Added reactivity
56

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

89
export default class inputRichTextFSC_LWC extends LightningElement {
910

1011
//Input and Output Attributes for Flow
11-
@api value; //set empty in connectedCallback if undefined.
12+
_value;
13+
@api
14+
set value(newValue) {
15+
if (newValue !== this._value) {
16+
this._value = newValue;
17+
this.connectedCallback();
18+
}
19+
}
20+
get value() {
21+
return this._value;
22+
}
23+
1224
@api disableAdvancedTools = false;
1325
@api disallowedWordsList;
1426
@api disallowedSymbolsList;
@@ -84,13 +96,13 @@ export default class inputRichTextFSC_LWC extends LightningElement {
8496
regTerm = '';
8597
applyTerm = '';
8698
instructions = '1) Find and Replace: Use Magnifying Glass, Enter Terms and Use Check Mark. '+
87-
'2) Auto Replace: If your Admin has configured it, Use Merge Icon to replace suggested terms.';
99+
'2) Auto Replace: If your Admin has configured it, Use Merge Icon to replace suggested terms.';
88100

89101
//Begin functionality
90102

91103
//Set initial values on load
92104
connectedCallback() {
93-
105+
94106
//use sessionStorage to fetch and restore latest value before validation failure.
95107
if(sessionStorage){
96108
if(sessionStorage.getItem('tempValue')){
@@ -103,58 +115,57 @@ export default class inputRichTextFSC_LWC extends LightningElement {
103115
this.formats = this.enabledFormats.split(',').map(function(item) {
104116
return item.trim();
105117
});
106-
}
118+
}
107119

108120
if(!this.disableAdvancedTools){
109-
console.log('disableAdvancedTools is false, in connected callback');
110-
(this.value != undefined) ? this.richText = this.value : this.richText = '';
121+
(this.value !== undefined) ? this.richText = this.value : this.richText = '';
111122
this.characterCount = this.richText.length;
112-
if(this.disallowedSymbolsList != undefined){
123+
if(this.disallowedSymbolsList !== undefined){
113124
this.disallowedSymbolsArray = this.disallowedSymbolsList.replace(/\s/g,'').split(',');
114125
for(let i=0; i<this.disallowedSymbolsArray.length; i++){
115126
if(i == 0){
116-
if(this.disallowedSymbolsArray.length != 1){
127+
if(this.disallowedSymbolsArray.length !== 1){
117128
this.disallowedSymbols = '['+ this.disallowedSymbolsArray[i] + '|';
118129
}else{
119130
this.disallowedSymbols = '['+ this.disallowedSymbolsArray[i] + ']';
120131
}
121-
} else if (i == (this.disallowedSymbolsArray.length - 1)){
132+
} else if (i === (this.disallowedSymbolsArray.length - 1)){
122133
this.disallowedSymbols = this.disallowedSymbols.concat(this.disallowedSymbolsArray[i] + ']');
123134
} else {
124135
this.disallowedSymbols = this.disallowedSymbols.concat(this.disallowedSymbolsArray[i] + '|');
125136
}
126137
}
127138
}
128-
129-
if(this.disallowedWordsList != undefined){
139+
140+
if(this.disallowedWordsList !== undefined){
130141
this.disallowedWordsArray = this.disallowedWordsList.replace(/\s/g,'').split(',');
131142
for(let i=0; i<this.disallowedWordsArray.length; i++){
132143
if(i == 0){
133-
if(this.disallowedWordsArray.length != 1){
144+
if(this.disallowedWordsArray.length !== 1){
134145
this.disallowedWords = '('+this.disallowedWordsArray[i] + '|';
135146
}else{
136147
this.disallowedWords = '('+this.disallowedWordsArray[i] + ')\b';
137148
}
138-
} else if (i == (this.disallowedWordsArray.length - 1)){
149+
} else if (i === (this.disallowedWordsArray.length - 1)){
139150
this.disallowedWords = this.disallowedWords.concat(this.disallowedWordsArray[i] + ')\\b');
140151
} else {
141152
this.disallowedWords = this.disallowedWords.concat(this.disallowedWordsArray[i] + '|');
142153
}
143154
}
144155
}
145-
if(this.disallowedSymbols != undefined) this.symbolsNotAllowed = new RegExp(this.disallowedSymbols,'g');
146-
if(this.disallowedWords != undefined) this.wordsNotAllowed = new RegExp(this.disallowedWords,'g');
147-
if(this.autoReplaceMap != undefined){
156+
if(this.disallowedSymbols !== undefined) this.symbolsNotAllowed = new RegExp(this.disallowedSymbols,'g');
157+
if(this.disallowedWords !== undefined) this.wordsNotAllowed = new RegExp(this.disallowedWords,'g');
158+
if(this.autoReplaceMap !== undefined){
148159
this.replaceMap = JSON.parse(this.autoReplaceMap);
149160
this.autoReplaceEnabled = true;
150-
}
161+
}
151162
if(this.characterLimit > 0){
152163
this.characterCap = true;
153164
}
154165
}
155166
}
156-
157-
//Handle updates to Rich Text field with no enhanced features
167+
168+
//Handle updates to Rich Text field with no enhanced features
158169
handleValueChange(event) {
159170
this.value = event.target.value;
160171
}
@@ -163,12 +174,12 @@ export default class inputRichTextFSC_LWC extends LightningElement {
163174
handleTextChange(event) {
164175
this.runningBlockedInput = [];
165176
this.isValidCheck = true;
166-
if (this.symbolsNotAllowed != undefined || this.wordsNotAllowed != undefined) {
177+
if (this.symbolsNotAllowed !== undefined || this.wordsNotAllowed !== undefined) {
167178
this.interimValue = (event.target.value).toLowerCase();
168179
this.interimValue = this.interimValue.replace(/(<([^>]+)>)/ig, "");
169-
180+
170181
//Symbol check section
171-
if (this.symbolsNotAllowed != undefined) {
182+
if (this.symbolsNotAllowed !== undefined) {
172183
let matchesSymbol = this.interimValue.match(this.symbolsNotAllowed);
173184
if (matchesSymbol != null && matchesSymbol.length > 0) {
174185
for(let i = 0; i < matchesSymbol.length; i++){
@@ -180,7 +191,7 @@ export default class inputRichTextFSC_LWC extends LightningElement {
180191
}
181192
}
182193

183-
if (this.wordsNotAllowed != undefined) {
194+
if (this.wordsNotAllowed !== undefined) {
184195
let matchesWords = this.interimValue.match(this.wordsNotAllowed);
185196
if (matchesWords != null && matchesWords.length > 0) {
186197
for(let i = 0; i < matchesWords.length; i++){
@@ -213,7 +224,7 @@ export default class inputRichTextFSC_LWC extends LightningElement {
213224
}else{
214225
this.errorMessage = 'Warning - Invalid Symbols/Words found: '+this.runningBlockedInput.toString();
215226
}
216-
227+
217228
}
218229

219230
//Set css on Character count if passing character limit
@@ -277,4 +288,4 @@ export default class inputRichTextFSC_LWC extends LightningElement {
277288
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
278289
}
279290

280-
}
291+
}

flow_screen_components/richTextInputFSC/force-app/main/default/lwc/inputRichTextFSC/inputRichTextFSC.js-meta.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="Rich Text Area FSC">
3-
<apiVersion>56.0</apiVersion>
3+
<apiVersion>62.0</apiVersion>
44
<isExposed>true</isExposed>
55
<targets>
66
<target>lightning__FlowScreen</target>
@@ -21,4 +21,4 @@
2121
<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."/>
2222
</targetConfig>
2323
</targetConfigs>
24-
</LightningComponentBundle>
24+
</LightningComponentBundle>

0 commit comments

Comments
 (0)