victorjonsson / jQuery-Form-Validator

[DISCONTINUED] jQuery plugin that makes it easy to validate user input while keeping your HTML markup clean from javascript code.
972 stars 476 forks source link

"depends-on-value" and negative values #688

Open lllopo opened 6 years ago

lllopo commented 6 years ago

Hi, I'm trying to make an inut working with "depends-on-value" property, which depends on "-1". Since the regex in the split function is "'[,|'+(allowSpaceAsDelimiter ? '\s':'')+'-]\s*'" , which means it splits on "," , "|" and "-" if I get it right and so - depending on a negative value seems rather impossible. The split actually converts the "-1" to an array of "empty" and "1". Is this correct or I'm missing something ? If it is correct - then this seems to be a huge shortcoming, then.

wunc commented 5 years ago

Having the same problem. For myself, I've addressed this by changing logic.js

listWithRequiredValues = $.split($input.valAttr('depends-on-value'), false, false),

to

listWithRequiredValues = $input.valAttr('depends-on-value').split(/[,|]\s*/),

I actually think a better delimiter is an unlikely-to-be-used character like the pipe |, or perhaps the double-pipe ||, but this would potentially be a breaking change to anyone who was using dashes as delimiter (but seriously, who does that?).