Skip to content

Commit

Permalink
control/bug getodk#157: fix two minor issues with numeric range.
Browse files Browse the repository at this point in the history
* default values were floats rather than strings. when one edits the
  textbox it drops strings in, so we should emulate that.
* zero and negative values should not be permitted for step.
  • Loading branch information
issa-tseng committed Jul 18, 2017
1 parent 1dfe6bd commit 8684921
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion public/javascripts/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@
inclusivity: false,
description: 'The lowest and highest selectable values, inclusive.',
tips: [ 'Integers and decimals are both valid.' ],
value: { min: 1, max: 10 },
value: { min: "1", max: "10" },
summary: false },
selectStep: { name: 'Selectable Range: Step Between Choices',
type: 'text',
Expand Down
5 changes: 4 additions & 1 deletion public/javascripts/impl.validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@
check: function(step, range)
{
// can't use % because js float nastiness.
var quotient = (parseFloat(range.max) - parseFloat(range.min)) / parseFloat(step);
var step = parseFloat(step);
if (step <= 0) return false;

var quotient = (parseFloat(range.max) - parseFloat(range.min)) / step;
return Math.floor(quotient) === quotient;
},
message: 'Step must divide the selectable range perfectly into evenly-sized increments.',
Expand Down

0 comments on commit 8684921

Please sign in to comment.