Skip to content

Commit

Permalink
Bug/multiple of with a float (rjsf-team#1000)
Browse files Browse the repository at this point in the history
* Added multipleOfPrecision setting to ajv settings

* Cs-format
  • Loading branch information
llamamoray authored and glasserc committed Aug 24, 2018
1 parent aadbbe9 commit 4a653fc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/components/fields/UnsupportedField.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ function UnsupportedField({ schema, idSchema, reason }) {
return (
<div className="unsupported-field">
<p>
Unsupported field schema{idSchema &&
Unsupported field schema
{idSchema &&
idSchema.$id && (
<span>
{" for"} field <code>{idSchema.$id}</code>
Expand Down
1 change: 1 addition & 0 deletions src/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Ajv from "ajv";
const ajv = new Ajv({
errorDataPath: "property",
allErrors: true,
multipleOfPrecision: 8,
});
// add custom formats
ajv.addFormat(
Expand Down
25 changes: 25 additions & 0 deletions test/validate_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,31 @@ describe("Validation", () => {
});
});

describe("Validating multipleOf with a float", () => {
const schema = {
type: "object",
properties: {
price: {
title: "Price per task ($)",
type: "number",
multipleOf: 0.01,
minimum: 0,
},
},
};

let errors;

beforeEach(() => {
const result = validateFormData({ price: 0.14 }, schema);
errors = result.errors;
});

it("should not return an error", () => {
expect(errors).to.have.length.of(0);
});
});

describe("Custom validate function", () => {
let errors, errorSchema;

Expand Down

0 comments on commit 4a653fc

Please sign in to comment.