Permalink
Browse files

Add support for `multipleOf` when using range input. Fixes #17

  • Loading branch information...
jdorn committed Dec 11, 2013
1 parent d81479b commit 1c0f157c6c87a9734cb8451cfcf29fbb37d97db7
Showing with 26 additions and 5 deletions.
  1. +1 −0 .gitignore
  2. +12 −2 dist/jquery.jsoneditor.js
  3. +1 −1 dist/jquery.jsoneditor.min.js
  4. +12 −2 src/editors/string.js
View
@@ -1 +1,2 @@
/node_modules/
/.idea/
View
@@ -289,8 +289,18 @@
// Set the min/max for format="range"
if(this.input_type === 'range') {
this.input.attr('min',(this.schema.minimum || 0));
this.input.attr('max',(this.schema.maximum || 100));
var min = this.schema.minimum || 0;
var max = this.schema.maximum || 100;
// If multipleOf is set, make sure minimum and maximum are multiples of multipleOf
if(this.schema.multipleOf) {
if(min%this.schema.multipleOf) min = Math.ceil(min/this.schema.multipleOf)*this.schema.multipleOf;
if(max%this.schema.multipleOf) max = Math.floor(max/this.schema.multipleOf)*this.schema.multipleOf;
this.input.attr('step',this.schema.multipleOf);
}
this.input.attr('min',min);
this.input.attr('max',max);
this.input.css({
marginBottom: '10px'
});

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -35,8 +35,18 @@
// Set the min/max for format="range"
if(this.input_type === 'range') {
this.input.attr('min',(this.schema.minimum || 0));
this.input.attr('max',(this.schema.maximum || 100));
var min = this.schema.minimum || 0;
var max = this.schema.maximum || 100;
// If multipleOf is set, make sure minimum and maximum are multiples of multipleOf
if(this.schema.multipleOf) {
if(min%this.schema.multipleOf) min = Math.ceil(min/this.schema.multipleOf)*this.schema.multipleOf;
if(max%this.schema.multipleOf) max = Math.floor(max/this.schema.multipleOf)*this.schema.multipleOf;
this.input.attr('step',this.schema.multipleOf);
}
this.input.attr('min',min);
this.input.attr('max',max);
this.input.css({
marginBottom: '10px'
});

0 comments on commit 1c0f157

Please sign in to comment.