nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: mozilla-services/react-jsonschema-form
Pull request #34 (2016-01-28 17:21:38)

Allow user to provide custom buttons to the form
Refs #33 


Patch:
diff --git a/README.md b/README.md
index e612c42e8..dc2c91bd0 100644
--- a/README.md
+++ b/README.md
@@ -231,6 +231,22 @@ render((
 
 If you're curious how this could ever be useful, have a look at the [Kinto formbuilder](https://github.com/Kinto/formbuilder) repository to see how it's used to provide editing capabilities to any form field.
 
+## Custom buttons
+
+You can provide custom buttons to your form via the `Form` component's `children`. A default submit button will be rendered if you don't provide children to the `Form` component.
+
+```jsx
+render(
+  <Form schema={schema}>
+    <div>
+      <button type="submit">Submit</button>
+      <button>Cancel</button>
+    </div>
+  </Form>);
+```
+
+**Warning:** there should be a button or an input with `type="submit"` to trigger the form submission (and then the form validation).
+
 ## Development server
 
 ```
diff --git a/src/components/Form.js b/src/components/Form.js
index 0df9cac4d..6ca7dfede 100644
--- a/src/components/Form.js
+++ b/src/components/Form.js
@@ -74,7 +74,7 @@ export default class Form extends Component {
   }
 
   render() {
-    const {schema, uiSchema} = this.props;
+    const {children, schema, uiSchema} = this.props;
     const {formData} = this.state;
     const _SchemaField = this.props.SchemaField || SchemaField;
     return (
@@ -86,7 +86,7 @@ export default class Form extends Component {
           formData={formData}
           onChange={this.onChange.bind(this)}
           SchemaField={_SchemaField}/>
-        <p><button type="submit">Submit</button></p>
+        { children ? children : <p><button type="submit">Submit</button></p> }
       </form>
     );
   }


Test patch:
diff --git a/test/index_test.js b/test/index_test.js
index ecc3ddd09..a828f085f 100644
--- a/test/index_test.js
+++ b/test/index_test.js
@@ -43,6 +43,36 @@ describe("Form", () => {
       expect(node.querySelectorAll("button[type=submit]"))
         .to.have.length.of(1);
     });
+
+    it("should render children buttons", () => {
+      const props = {schema: {}};
+      const comp = renderIntoDocument(
+        <Form {...props}>
+          <button type="submit">Submit</button>
+          <button type="submit">Another submit</button>
+        </Form>
+      );
+      const node = findDOMNode(comp);
+      expect(node.querySelectorAll("button[type=submit]"))
+        .to.have.length.of(2);
+    });
+  });
+
+  describe("Custom submit buttons", () => {
+    it("should submit the form when clicked", () => {
+      const onSubmit = sandbox.spy();
+      const comp = renderIntoDocument(
+        <Form onSubmit={ onSubmit } schema={ {} }>
+          <button type="submit">Submit</button>
+          <button type="submit">Another submit</button>
+        </Form>
+      );
+      const node = findDOMNode(comp);
+      const buttons = node.querySelectorAll("button[type=submit]");
+      buttons[0].click();
+      buttons[1].click();
+      sinon.assert.calledTwice(onSubmit);
+    });
   });
 
   describe("Custom SchemaField", () => {
Repository: mozilla-services/react-jsonschema-form
Pull request #53 (2016-03-08 17:33:55)

Closes #36: Ensure formData are properly validated when schema is updated
Refs and supersedes #36.

@fangj, could you please check the diff and see if that addresses your initial issue? Thanks! 


Patch:
diff --git a/src/components/Form.js b/src/components/Form.js
index 933ba6d14..224eaec4a 100644
--- a/src/components/Form.js
+++ b/src/components/Form.js
@@ -20,19 +20,20 @@ export default class Form extends Component {
   }
 
   getStateFromProps(props) {
+    const schema = "schema" in props ? props.schema : this.props.schema;
     const edit = !!props.formData;
-    const formData = props.formData || getDefaultFormState(props.schema) || null;
+    const formData = props.formData || getDefaultFormState(schema) || null;
     return {
       status: "initial",
       formData,
       edit,
-      errors: edit ? this.validate(formData) : []
+      errors: edit ? this.validate(formData, schema) : []
     };
   }
 
-  validate(formData) {
+  validate(formData, schema) {
     const validator = new Validator();
-    return validator.validate(formData, this.props.schema).errors;
+    return validator.validate(formData, schema || this.props.schema).errors;
   }
 
   renderErrors() {
diff --git a/src/components/fields/SchemaField.js b/src/components/fields/SchemaField.js
index ffa3f2399..c82dbf570 100644
--- a/src/components/fields/SchemaField.js
+++ b/src/components/fields/SchemaField.js
@@ -57,7 +57,7 @@ if (process.env.NODE_ENV !== "production") {
     type: PropTypes.string.isRequired,
     label: PropTypes.string,
     required: PropTypes.bool,
-    displayLabel: PropTypes.bool,
+    isEnum: PropTypes.bool,
     children: React.PropTypes.node.isRequired,
     classNames: React.PropTypes.string,
   };


Test patch:
diff --git a/test/index_test.js b/test/index_test.js
index d6791c871..e051054c8 100644
--- a/test/index_test.js
+++ b/test/index_test.js
@@ -1391,6 +1391,16 @@ describe("Form", () => {
 
         expect(comp.state.formData).eql("yo");
       });
+
+      it("should validate formData when the schema is updated", () => {
+        const {comp} = createComponent({schema: {type: "string"}});
+
+        comp.componentWillReceiveProps({formData: "yo", schema: {type: "number"}});
+
+        expect(comp.state.errors).to.have.length.of(1);
+        expect(comp.state.errors[0].stack)
+          .to.eql("instance is not of a type(s) number");
+      });
     });
 
     describe("object level", () => {
Repository: mozilla-services/react-jsonschema-form
Pull request #73 (2016-03-18 15:21:59)

Use first enum item default when no default is provided
Feedback=? @magopian 


Patch:
diff --git a/README.md b/README.md
index 28b263e93..dc6c8eefa 100644
--- a/README.md
+++ b/README.md
@@ -25,6 +25,7 @@ A [live demo](https://mozilla-services.github.io/react-jsonschema-form/) is host
   - [Custom SchemaField](#custom-schemafield)
   - [Custom titles](#custom-titles)
   - [Custom buttons](#custom-buttons)
+  - [Schema definitions &amp; references](#schema-definitions-amp-references)
   - [Development server](#development-server)
   - [Tests](#tests)
      - [TDD](#tdd)
diff --git a/src/utils.js b/src/utils.js
index f224c2ff7..afcb08e49 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -72,6 +72,9 @@ function computeDefaults(schema, parentDefaults, definitions={}) {
   } else if ("default" in schema) {
     // Use schema defaults for this node.
     defaults = schema.default;
+  } else if ("enum" in schema && Array.isArray(schema.enum)) {
+    // For enum with no defined default, select the first entry.
+    defaults = schema.enum[0];
   } else if ("$ref" in schema) {
     // Use referenced schema defaults for this node.
     const refSchema = findSchemaDefinition(schema.$ref, definitions);


Test patch:
diff --git a/test/utils_test.js b/test/utils_test.js
index 19afbf91d..3a6f9223b 100644
--- a/test/utils_test.js
+++ b/test/utils_test.js
@@ -171,6 +171,19 @@ describe("utils", () => {
           .eql({level1: [1, 2, 3]});
       });
 
+      it("should use first enum value when no default is specified", () => {
+        const schema = {
+          type: "object",
+          properties: {
+            foo: {
+              type: "string",
+              enum: ["a", "b", "c"],
+            }
+          }
+        };
+        expect(getDefaultFormState(schema, {}))
+          .eql({foo: "a"});
+      });
     });
   });
Repository: mozilla-services/react-jsonschema-form
Pull request #334 (2016-10-06 14:29:27)

Properly handle numbers that require trailing zeroes
## Situation
We ran into this issue entering dollar amounts where the user intends to enter a monetary value with several trailing digits to match locale - such as "12.90" or "12.00".

## Current behavior
Current behavior is that upon entering the trailing zero, it is immediately stripped and shows the user "12.9" or "12", respectively.

## Desired behavior
Show the user what they entered after validating - "12.90" or "12.00", respectively.

israelshirk: (Update 8:40AM US/Denver - resolved an issue in which the test was in the wrong section)
n1k0: Great patch, thanks a lot for your contribution.

Patch:
diff --git a/src/utils.js b/src/utils.js
index 36372dc64..e71751bf0 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -224,6 +224,14 @@ export function asNumber(value) {
   }
   const n = Number(value);
   const valid = typeof n === "number" && !Number.isNaN(n);
+
+  if (/\.\d*0$/.test(value)) {
+    // It's a number, that's cool - but we need it as a string so it doesn't screw
+    // with the user when entering dollar amounts or other values (such as those with
+    // specific precision or number of significant digits)
+    return value;
+  }
+
   return valid ? n : value;
 }
 


Test patch:
diff --git a/test/NumberField_test.js b/test/NumberField_test.js
index 97b191e7e..d3dce39b8 100644
--- a/test/NumberField_test.js
+++ b/test/NumberField_test.js
@@ -102,6 +102,36 @@ describe("NumberField", () => {
       expect(node.querySelector("input[type=text]").id)
         .eql("root");
     });
+
+    it("should render with trailing zeroes", () => {
+      const {node} = createFormComponent({schema: {
+        type: "number"
+      }});
+
+      Simulate.change(node.querySelector("input"), {
+        target: {value: "2."}
+      });
+      expect(node.querySelector(".field input").value)
+        .eql("2.");
+
+      Simulate.change(node.querySelector("input"), {
+        target: {value: "2.0"}
+      });
+      expect(node.querySelector(".field input").value)
+        .eql("2.0");
+
+      Simulate.change(node.querySelector("input"), {
+        target: {value: "2.00"}
+      });
+      expect(node.querySelector(".field input").value)
+        .eql("2.00");
+
+      Simulate.change(node.querySelector("input"), {
+        target: {value: "2.000"}
+      });
+      expect(node.querySelector(".field input").value)
+        .eql("2.000");
+    });
   });
 
   describe("SelectWidget", () => {
Repository: mozilla-services/react-jsonschema-form
Pull request #428 (2016-12-06 13:00:30)

Wrap radio and checkbox labels into span to enable styling.
### Reasons for making this change

This allows labels to be styled using:
input + span
input:checked + span

Also changed `strong` to `span` to be consistent.

Some conversation:
https://github.com/mozilla-services/react-jsonschema-form/pull/403

### Checklist
* [x] **I'm adding or updating code**
* [x] **I'm updated test**

No docs are needed.


Patch:
diff --git a/src/components/widgets/CheckboxWidget.js b/src/components/widgets/CheckboxWidget.js
index 94e306bc3..d65c66355 100644
--- a/src/components/widgets/CheckboxWidget.js
+++ b/src/components/widgets/CheckboxWidget.js
@@ -21,7 +21,7 @@ function CheckboxWidget({
           disabled={disabled}
           autoFocus={autofocus}
           onChange={(event) => onChange(event.target.checked)}/>
-        <strong>{label}</strong>
+        <span>{label}</span>
       </label>
     </div>
   );
diff --git a/src/components/widgets/CheckboxesWidget.js b/src/components/widgets/CheckboxesWidget.js
index d0224bef5..d6471a409 100644
--- a/src/components/widgets/CheckboxesWidget.js
+++ b/src/components/widgets/CheckboxesWidget.js
@@ -36,7 +36,7 @@ function CheckboxesWidget(props) {
                   onChange(deselectValue(option.value, value));
                 }
               }}/>
-            {option.label}
+            <span>{option.label}</span>
           </span>
         );
         return inline ? (
diff --git a/src/components/widgets/RadioWidget.js b/src/components/widgets/RadioWidget.js
index 43ddbcdda..717bcd4e8 100644
--- a/src/components/widgets/RadioWidget.js
+++ b/src/components/widgets/RadioWidget.js
@@ -29,7 +29,7 @@ function RadioWidget({
               disabled={disabled}
               autoFocus={autofocus && i === 0}
               onChange={_ => onChange(option.value)}/>
-            {option.label}
+            <span>{option.label}</span>
           </span>
         );
 


Test patch:
diff --git a/test/BooleanField_test.js b/test/BooleanField_test.js
index a7b75e583..294864491 100644
--- a/test/BooleanField_test.js
+++ b/test/BooleanField_test.js
@@ -33,7 +33,7 @@ describe("BooleanField", () => {
       title: "foo"
     }});
 
-    expect(node.querySelector(".field label strong").textContent)
+    expect(node.querySelector(".field label span").textContent)
       .eql("foo");
   });
Repository: mozilla-services/react-jsonschema-form
Pull request #519 (2017-03-21 08:22:09)

Fix impossibility to use stateful ArrayFieldTeplate comp.
Specifically addresses https://github.com/mozilla-services/react-jsonschema-form/pull/304#issuecomment-287879581


Patch:
diff --git a/src/components/fields/ArrayField.js b/src/components/fields/ArrayField.js
index 1b600b7ce..0f9e1d37f 100644
--- a/src/components/fields/ArrayField.js
+++ b/src/components/fields/ArrayField.js
@@ -333,9 +333,8 @@ class ArrayField extends Component {
     };
 
     // Check if a custom render function was passed in
-    const renderFunction = ArrayFieldTemplate ||
-      DefaultNormalArrayFieldTemplate;
-    return renderFunction(arrayProps);
+    const Component = ArrayFieldTemplate || DefaultNormalArrayFieldTemplate;
+    return <Component {...arrayProps} />;
   }
 
   renderMultiSelect() {


Test patch:
diff --git a/test/ArrayFieldTemplate_test.js b/test/ArrayFieldTemplate_test.js
index b6b8ee3a0..128d1ec1a 100644
--- a/test/ArrayFieldTemplate_test.js
+++ b/test/ArrayFieldTemplate_test.js
@@ -1,4 +1,4 @@
-import React from "react";
+import React, { PureComponent } from "react";
 
 import { expect } from "chai";
 import { createFormComponent, createSandbox } from "./test_utils";
@@ -6,6 +6,8 @@ import { createFormComponent, createSandbox } from "./test_utils";
 describe("ArrayFieldTemplate", () => {
   let sandbox;
 
+  const formData = ["one", "two", "three"];
+
   beforeEach(() => {
     sandbox = createSandbox();
   });
@@ -35,7 +37,23 @@ describe("ArrayFieldTemplate", () => {
       );
     }
 
-    const formData = ["one", "two", "three"];
+    describe("Statefull ArrayFieldTemplate", () => {
+      class ArrayFieldTemplate extends PureComponent {
+        render() {
+          return <div>{this.props.items.map(item => item.element)}</div>;
+        }
+      }
+
+      it("should render a stateful custom component", () => {
+        const { node } = createFormComponent({
+          schema: { type: "array", items: { type: "string" } },
+          formData,
+          ArrayFieldTemplate,
+        });
+
+        expect(node.querySelectorAll(".field-array div")).to.have.length.of(3);
+      });
+    });
 
     describe("not fixed items", () => {
       const schema = {
@@ -46,6 +64,7 @@ describe("ArrayFieldTemplate", () => {
       };
 
       let node;
+
       beforeEach(() => {
         node = createFormComponent({
           ArrayFieldTemplate,
Repository: mozilla-services/react-jsonschema-form
Pull request #589 (2017-05-24 20:45:43)

Fixes default value for object missing properties
### Reasons for making this change

When the schema of a field of type object is missing the `properties` key, it raises an exception: `Cannot convert undefined or null to object`. This PR fixes it by defaulting the value to an empty object, this way, we can use custom fields to render objects without defined properties.

vierno: Hello @n1k0 , I made the requested changes, thanks!

Patch:
diff --git a/src/utils.js b/src/utils.js
index d8721d686..a3a7b3eca 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -128,7 +128,7 @@ function computeDefaults(schema, parentDefaults, definitions = {}) {
   switch (schema.type) {
     // We need to recur for object schema inner default values.
     case "object":
-      return Object.keys(schema.properties).reduce((acc, key) => {
+      return Object.keys(schema.properties || {}).reduce((acc, key) => {
         // Compute the defaults for this node, with the parent defaults we might
         // have from a previous run: defaults[key].
         acc[key] = computeDefaults(


Test patch:
diff --git a/test/utils_test.js b/test/utils_test.js
index ad42abd5d..56fbc73db 100644
--- a/test/utils_test.js
+++ b/test/utils_test.js
@@ -43,6 +43,14 @@ describe("utils", () => {
         ).to.eql({ string: "foo" });
       });
 
+      it("should default to empty object if no properties are defined", () => {
+        expect(
+          getDefaultFormState({
+            type: "object",
+          })
+        ).to.eql({});
+      });
+
       it("should recursively map schema object default to form state", () => {
         expect(
           getDefaultFormState({
Repository: mozilla-services/react-jsonschema-form
Pull request #590 (2017-05-25 20:18:05)

Fixes array without items for custom fields
### Reasons for making this change

The jsonschema of an array may omit the `items` property, similarly to #589, with this fix it's possible to create a field for custom arrays without items defined by the schema.


n1k0: :+1: 

Patch:
diff --git a/src/utils.js b/src/utils.js
index a3a7b3eca..cf2e511a4 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -278,12 +278,16 @@ export function orderProperties(properties, order) {
 }
 
 export function isMultiSelect(schema) {
-  return Array.isArray(schema.items.enum) && schema.uniqueItems;
+  return schema.items
+    ? Array.isArray(schema.items.enum) && schema.uniqueItems
+    : false;
 }
 
 export function isFilesArray(schema, uiSchema) {
   return (
-    (schema.items.type === "string" && schema.items.format === "data-url") ||
+    (schema.items &&
+      schema.items.type === "string" &&
+      schema.items.format === "data-url") ||
     uiSchema["ui:widget"] === "files"
   );
 }


Test patch:
diff --git a/test/utils_test.js b/test/utils_test.js
index 56fbc73db..aaa7c3dba 100644
--- a/test/utils_test.js
+++ b/test/utils_test.js
@@ -5,6 +5,7 @@ import {
   dataURItoBlob,
   deepEquals,
   getDefaultFormState,
+  isFilesArray,
   isMultiSelect,
   mergeObjects,
   pad,
@@ -274,6 +275,11 @@ describe("utils", () => {
       expect(isMultiSelect(schema)).to.be.true;
     });
 
+    it("should be false if items is undefined", () => {
+      const schema = {};
+      expect(isMultiSelect(schema)).to.be.false;
+    });
+
     it("should be false if uniqueItems is false", () => {
       const schema = { items: { enum: ["foo", "bar"] }, uniqueItems: false };
       expect(isMultiSelect(schema)).to.be.false;
@@ -285,6 +291,20 @@ describe("utils", () => {
     });
   });
 
+  describe("isFilesArray()", () => {
+    it("should be true if items have data-url format", () => {
+      const schema = { items: { type: "string", format: "data-url" } };
+      const uiSchema = {};
+      expect(isFilesArray(schema, uiSchema)).to.be.true;
+    });
+
+    it("should be false if items is undefined", () => {
+      const schema = {};
+      const uiSchema = {};
+      expect(isFilesArray(schema, uiSchema)).to.be.false;
+    });
+  });
+
   describe("mergeObjects()", () => {
     it("should't mutate the provided objects", () => {
       const obj1 = { a: 1 };
Repository: mozilla-services/react-jsonschema-form
Pull request #668 (2017-08-15 17:48:09)

66 enum no type
### Reasons for making this change

JSON Schema states enums can be used without defining type => default type to string when not specified.

See #66 #611 

### Checklist


* [x] **I'm adding or updating code**
  - [x] I've added and/or updated tests
  - [x] I've updated docs if needed
  - [x] I've run `npm run cs-format` on my branch to conform my code to [prettier](https://github.com/prettier/prettier) coding style




Patch:
diff --git a/src/components/fields/SchemaField.js b/src/components/fields/SchemaField.js
index 4c9b109cb..0b3a0aeac 100644
--- a/src/components/fields/SchemaField.js
+++ b/src/components/fields/SchemaField.js
@@ -8,6 +8,7 @@ import {
   getUiOptions,
   isFilesArray,
   deepEquals,
+  getSchemaType,
 } from "../../utils";
 import UnsupportedField from "./UnsupportedField";
 
@@ -29,7 +30,8 @@ function getFieldComponent(schema, uiSchema, idSchema, fields) {
   if (typeof field === "string" && field in fields) {
     return fields[field];
   }
-  const componentName = COMPONENT_TYPES[schema.type];
+
+  const componentName = COMPONENT_TYPES[getSchemaType(schema)];
   return componentName in fields
     ? fields[componentName]
     : () => {
diff --git a/src/utils.js b/src/utils.js
index d57ab7761..ec0033284 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -62,8 +62,16 @@ export function getDefaultRegistry() {
   };
 }
 
+export function getSchemaType(schema) {
+  let { type } = schema;
+  if (!type && schema.enum) {
+    type = "string";
+  }
+  return type;
+}
+
 export function getWidget(schema, widget, registeredWidgets = {}) {
-  const { type } = schema;
+  const type = getSchemaType(schema);
 
   function mergeOptions(Widget) {
     // cache return value as property of widget for proper react reconciliation


Test patch:
diff --git a/test/StringField_test.js b/test/StringField_test.js
index e25af5b4b..ef65f72da 100644
--- a/test/StringField_test.js
+++ b/test/StringField_test.js
@@ -191,6 +191,16 @@ describe("StringField", () => {
       expect(node.querySelectorAll(".field select")).to.have.length.of(1);
     });
 
+    it("should render a string field for an enum without a type", () => {
+      const { node } = createFormComponent({
+        schema: {
+          enum: ["foo", "bar"],
+        },
+      });
+
+      expect(node.querySelectorAll(".field select")).to.have.length.of(1);
+    });
+
     it("should render a string field with a label", () => {
       const { node } = createFormComponent({
         schema: {