Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Live omit #1332

Merged
merged 4 commits into from
Jun 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ render((
), document.getElementById("app"));
```

> Note: If there are fields in the `formData` that are not represented in the schema, they will be retained by default. If you would like to remove those extra values on form submission, then set the `omitExtraData` prop to `true`.
> Note: If there are fields in the `formData` that are not represented in the schema, they will be retained by default. If you would like to remove those extra values on form submission, then set the `omitExtraData` prop to `true`. Set the `liveOmit` prop to true in order to remove extra data upon form data change.

#### Form error event handler

Expand All @@ -137,7 +137,7 @@ render((

If you plan on being notified every time the form data are updated, you can pass an `onChange` handler, which will receive the same args as `onSubmit` any time a value is updated in the form.

> Note: If `omitExtraData` and `liveValidate` are both set to true, then extra form data values that are not in any form field will be removed whenever `onChange` is called.
> Note: If `omitExtraData` and `liveOmit` are both set to true, then extra form data values that are not in any form field will be removed whenever `onChange` is called.

#### Form field blur events

Expand Down
5 changes: 4 additions & 1 deletion src/components/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export default class Form extends Component {
let state = { formData };
let newFormData = formData;

if (this.props.omitExtraData === true && this.props.liveValidate) {
if (this.props.omitExtraData === true && this.props.liveOmit === true) {
const newState = this.getStateFromProps(this.props, formData);

const fieldNames = this.getFieldNames(
Expand All @@ -184,6 +184,9 @@ export default class Form extends Component {
);

newFormData = this.getUsedFormData(formData, fieldNames);
state = {
formData: newFormData,
};
}

if (mustValidate) {
Expand Down
6 changes: 3 additions & 3 deletions test/Form_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ describe("Form", () => {
});
});

it("should call getUsedFormData when the omitExtraData prop is true and liveValidate is true", () => {
it("should call getUsedFormData when the omitExtraData prop is true and liveOmit is true", () => {
const schema = {
type: "object",
properties: {
Expand All @@ -1124,13 +1124,13 @@ describe("Form", () => {
};
const onChange = sandbox.spy();
const omitExtraData = true;
const liveValidate = true;
const liveOmit = true;
const { node, comp } = createFormComponent({
schema,
formData,
onChange,
omitExtraData,
liveValidate,
liveOmit,
});

sandbox.stub(comp, "getUsedFormData").returns({
Expand Down