Repository: mozilla-services/react-jsonschema-form
Pull request #344 (2016-10-17 21:19:38)

minimum and maximum props are not passed to UpDownWidget and RangeWidget
… when value === 0

n1k0: Thanks! Would you mind adding a test? :)
pabloen: Sure! here they are.
Btw, found and solved the same issue for RangeWidget.
n1k0: Awesome, thanks! Also, I'm realizing the `rangeSpec` functions are the same, would you mind factorizing them out in the `utils` module? That'd be just great :)
pabloen: Sure thing, glad to help!
This library have served me well.

Patch:
diff --git a/src/components/widgets/RangeWidget.js b/src/components/widgets/RangeWidget.js
index c8bc400dc..99bb9ec45 100644
--- a/src/components/widgets/RangeWidget.js
+++ b/src/components/widgets/RangeWidget.js
@@ -1,22 +1,8 @@
 import React, { PropTypes } from "react";
 
+import { rangeSpec } from "../../utils";
 import BaseInput from "./BaseInput";
 
-
-function rangeSpec(schema) {
-  const spec = {};
-  if (schema.multipleOf) {
-    spec.step = schema.multipleOf;
-  }
-  if (schema.minimum) {
-    spec.min = schema.minimum;
-  }
-  if (schema.maximum) {
-    spec.max = schema.maximum;
-  }
-  return spec;
-}
-
 function RangeWidget(props) {
   const {schema, value} = props;
   return (
diff --git a/src/components/widgets/UpDownWidget.js b/src/components/widgets/UpDownWidget.js
index 2ed97990f..d57b0bed9 100644
--- a/src/components/widgets/UpDownWidget.js
+++ b/src/components/widgets/UpDownWidget.js
@@ -1,22 +1,8 @@
 import React, { PropTypes } from "react";
 
+import { rangeSpec } from "../../utils";
 import BaseInput from "./BaseInput";
 
-
-function rangeSpec(schema) {
-  const spec = {};
-  if (schema.multipleOf) {
-    spec.step = schema.multipleOf;
-  }
-  if (schema.minimum) {
-    spec.min = schema.minimum;
-  }
-  if (schema.maximum) {
-    spec.max = schema.maximum;
-  }
-  return spec;
-}
-
 function UpDownWidget(props) {
   return <BaseInput type="number" {...props} {...rangeSpec(props.schema)} />;
 }
diff --git a/src/utils.js b/src/utils.js
index 2fbf03cb8..19692b7dd 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -500,3 +500,17 @@ export function dataURItoBlob(dataURI) {
 
   return {blob, name};
 }
+
+export function rangeSpec(schema) {
+  const spec = {};
+  if (schema.multipleOf) {
+    spec.step = schema.multipleOf;
+  }
+  if (schema.minimum || schema.minimum === 0) {
+    spec.min = schema.minimum;
+  }
+  if (schema.maximum || schema.maximum === 0) {
+    spec.max = schema.maximum;
+  }
+  return spec;
+}


Test patch:
diff --git a/test/uiSchema_test.js b/test/uiSchema_test.js
index 94c7a3f0a..cdcfb7d99 100644
--- a/test/uiSchema_test.js
+++ b/test/uiSchema_test.js
@@ -654,6 +654,20 @@ describe("uiSchema", () => {
           expect(input.getAttribute("max")).eql("100");
         });
 
+        it("should support '0' as minimum and maximum constraints", () => {
+          const schema = {
+            type: "number",
+            minimum: 0,
+            maximum: 0,
+          };
+          const uiSchema = {"ui:widget": "updown"};
+          const {node} = createFormComponent({schema, uiSchema});
+          input = node.querySelector("[type=number]");
+
+          expect(input.getAttribute("min")).eql("0");
+          expect(input.getAttribute("max")).eql("0");
+        });
+
         it("should support the multipleOf constraint", () => {
           expect(input.getAttribute("step")).eql("1");
         });
@@ -711,6 +725,20 @@ describe("uiSchema", () => {
           expect(input.getAttribute("max")).eql("100");
         });
 
+        it("should support '0' as minimum and maximum constraints", () => {
+          const schema = {
+            type: "number",
+            minimum: 0,
+            maximum: 0,
+          };
+          const uiSchema = {"ui:widget": "range"};
+          const {node} = createFormComponent({schema, uiSchema});
+          input = node.querySelector("[type=range]");
+
+          expect(input.getAttribute("min")).eql("0");
+          expect(input.getAttribute("max")).eql("0");
+        });
+
         it("should support the multipleOf constraint", () => {
           expect(input.getAttribute("step")).eql("1");
         });