Skip to content

Commit

Permalink
feat(form): replace all rule token instances in prompt message
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Joe-Soap authored Feb 15, 2020
1 parent fc74780 commit 2538a8e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/definitions/behaviors/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,18 +545,18 @@ $.fn.form = function(parameters) {
name
;
if(requiresValue) {
prompt = prompt.replace('{value}', $field.val());
prompt = prompt.replace(/\{value\}/g, $field.val());
}
if(requiresName) {
$label = $field.closest(selector.group).find('label').eq(0);
name = ($label.length == 1)
? $label.text()
: $field.prop('placeholder') || settings.text.unspecifiedField
;
prompt = prompt.replace('{name}', name);
prompt = prompt.replace(/\{name\}/g, name);
}
prompt = prompt.replace('{identifier}', field.identifier);
prompt = prompt.replace('{ruleValue}', ancillary);
prompt = prompt.replace(/\{identifier\}/g, field.identifier);
prompt = prompt.replace(/\{ruleValue\}/g, ancillary);
if(!rule.prompt) {
module.verbose('Using default validation prompt for type', prompt, ruleName);
}
Expand Down

0 comments on commit 2538a8e

Please sign in to comment.