Skip to content

Commit 2538a8e

Browse files
authored
feat(form): replace all rule token instances in prompt message
Within the prompt property method of the form module, I updated the replace calls, where it replaces contextual tokens relating to the rules definition, to use a regular expression of the same respective values in order to have it replace all tokens present in the prompt text. The tokens used are the following: identifier name ruleValue If one uses a singular token multiple times in the prompt, for example, { type: 'levelCheck[2]', prompt: 'Level {ruleValue} not detected. Please ensure that {name} is set to a level at least equal to {ruleValue}.' } the first token of {ruleValue} is successfully replaced, but the subsequent {ruleValue} isn't. This change merely applies a regex with the "global" flag set in order to replace multiple tokens of the same name found in the prompt text.
1 parent fc74780 commit 2538a8e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/definitions/behaviors/form.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,18 +545,18 @@ $.fn.form = function(parameters) {
545545
name
546546
;
547547
if(requiresValue) {
548-
prompt = prompt.replace('{value}', $field.val());
548+
prompt = prompt.replace(/\{value\}/g, $field.val());
549549
}
550550
if(requiresName) {
551551
$label = $field.closest(selector.group).find('label').eq(0);
552552
name = ($label.length == 1)
553553
? $label.text()
554554
: $field.prop('placeholder') || settings.text.unspecifiedField
555555
;
556-
prompt = prompt.replace('{name}', name);
556+
prompt = prompt.replace(/\{name\}/g, name);
557557
}
558-
prompt = prompt.replace('{identifier}', field.identifier);
559-
prompt = prompt.replace('{ruleValue}', ancillary);
558+
prompt = prompt.replace(/\{identifier\}/g, field.identifier);
559+
prompt = prompt.replace(/\{ruleValue\}/g, ancillary);
560560
if(!rule.prompt) {
561561
module.verbose('Using default validation prompt for type', prompt, ruleName);
562562
}

0 commit comments

Comments
 (0)