Skip to content

Commit

Permalink
fix(form): fetch range input prompt for numeric values only
Browse files Browse the repository at this point in the history
The check in the prompt assumed the rule value is a string, but it may also be a regex, which throws an exception.
Additionally, it can be a normal string with two dots, e.g. type: "contains[hello..world]" which shouldn't be treated as a range.
So I changed the check to also verify the type can contain a range, rather than just check if the value has two dots inside.

Given the rule { type: 'contains[hello...]' } the resulting prompt is Please enter a valid value and must be in a range from hello to . which is nonsense, since it checks whether the text contains the literal hello....

Given the rule { type: 'regExp', value: /hello/ } we get an exception Uncaught TypeError: ancillary.indexOf is not a function because ancillary is a RegExp and not a string, so doesn't have indexOf. Validation is then entirely broken.
  • Loading branch information
NotWearingPants committed Oct 23, 2021
1 parent d2b76da commit 1c5931a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/definitions/behaviors/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ $.fn.form = function(parameters) {
parts,
suffixPrompt
;
if(ancillary && ancillary.indexOf('..') >= 0) {
if(ancillary && ['integer', 'decimal', 'number'].indexOf(ruleName) >= 0 && ancillary.indexOf('..') >= 0) {
parts = ancillary.split('..', 2);
if(!rule.prompt) {
suffixPrompt = (
Expand Down

0 comments on commit 1c5931a

Please sign in to comment.