Skip to content

Commit

Permalink
form saving -> submitting
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Berney committed Nov 28, 2017
1 parent cc189c4 commit 15f0595
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions spec/pivotal-ui-react/form/form-col_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('FormCol', () => {
state: {
key: 'value',
current: {'some-name-set-on-the-col': 'current-value'},
saving: true
submitting: true
},
onChange: () => formOnChange
};
Expand All @@ -118,7 +118,7 @@ describe('FormCol', () => {
it('calls the children callback', () => {
expect(childrenSpy).toHaveBeenCalledWith({
...formProps,
saving: true,
submitting: true,
onChange: formOnChange
});
});
Expand Down
16 changes: 8 additions & 8 deletions spec/pivotal-ui-react/form/form_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ describe('Form', () => {
expect('.grid:eq(0) .col:eq(0) input').toHaveAttr('value', 'some-name');
});

it('renders Buttons with saving=false', () => {
it('renders Buttons with submitting=false', () => {
expect(Buttons).toHaveBeenCalledWith({
canSubmit: subject.canSubmit,
canReset: subject.canReset,
reset: subject.reset,
onSubmit: subject.onSubmit,
saving: false,
submitting: false,
setState: subject.setState,
state: subject.state,
onChange: jasmine.any(Function)
Expand Down Expand Up @@ -151,13 +151,13 @@ describe('Form', () => {
expect('.grid:eq(0) .col:eq(1) .cancel').toBeDisabled();
});

it('renders Buttons with saving=true', () => {
it('renders Buttons with submitting=true', () => {
expect(Buttons).toHaveBeenCalledWith({
canSubmit: subject.canSubmit,
canReset: subject.canReset,
reset: subject.reset,
onSubmit: subject.onSubmit,
saving: true,
submitting: true,
setState: subject.setState,
state: subject.state,
onChange: jasmine.any(Function)
Expand All @@ -174,13 +174,13 @@ describe('Form', () => {
expect('form > fieldset').not.toBeDisabled();
});

it('renders Buttons with saving=false', () => {
it('renders Buttons with submitting=false', () => {
expect(Buttons).toHaveBeenCalledWith({
canSubmit: subject.canSubmit,
canReset: subject.canReset,
reset: subject.reset,
onSubmit: subject.onSubmit,
saving: false,
submitting: false,
setState: subject.setState,
state: subject.state,
onChange: jasmine.any(Function)
Expand Down Expand Up @@ -226,13 +226,13 @@ describe('Form', () => {
expect('form > fieldset').not.toBeDisabled();
});

it('renders Buttons with saving=false', () => {
it('renders Buttons with submitting=false', () => {
expect(Buttons).toHaveBeenCalledWith({
canSubmit: subject.canSubmit,
canReset: subject.canReset,
reset: subject.reset,
onSubmit: subject.onSubmit,
saving: false,
submitting: false,
setState: subject.setState,
state: subject.state,
onChange: jasmine.any(Function)
Expand Down
2 changes: 1 addition & 1 deletion src/react/forms/form-col.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class FormCol extends React.Component {
canReset,
reset,
onSubmit,
saving: state.saving,
submitting: state.submitting,
setState,
state,
onChange: onChange ? onChange(name, validator) : () => null
Expand Down
18 changes: 9 additions & 9 deletions src/react/forms/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class Form extends React.Component {
this.state = {
initial,
current,
saving: false,
submitting: false,
errors: {},
requiredFields
};
Expand Down Expand Up @@ -121,8 +121,8 @@ export class Form extends React.Component {

canSubmit({checkRequiredFields} = {}) {
const {children} = this.props;
const {initial, current, saving, requiredFields} = this.state;
return !saving
const {initial, current, submitting, requiredFields} = this.state;
return !submitting
&& find(Object.keys(initial), key => !deepEqual(initial[key], current[key]))
&& (checkRequiredFields
? checkRequiredFields(this.state.current)
Expand All @@ -135,16 +135,16 @@ export class Form extends React.Component {
}

canReset() {
const {saving, initial, current} = this.state;
return !saving && !deepEqual(initial, current);
const {submitting, initial, current} = this.state;
return !submitting && !deepEqual(initial, current);
}

async onSubmit(e) {
e && e.preventDefault();
const {onSubmit, onSubmitError, afterSubmit, onModified, resetOnSubmit} = this.props;
const {initial, current} = this.state;
this.setState({saving: true});
const nextState = {saving: false};
this.setState({submitting: true});
const nextState = {submitting: false};
try {
const response = await onSubmit({initial, current});
this.setState({
Expand All @@ -170,7 +170,7 @@ export class Form extends React.Component {

render() {
const {className, children} = this.props;
const {saving} = this.state;
const {submitting} = this.state;
const filteredChildren = React.Children.toArray(children).filter(child => {
const childIsFormRow = child.type === FormRow || child.type.prototype instanceof FormRow;
if (!childIsFormRow) {
Expand All @@ -181,7 +181,7 @@ export class Form extends React.Component {

return (
<form {...{className: classnames('form', className), onSubmit: this.onSubmit}}>
<fieldset {...{disabled: saving}}>
<fieldset {...{disabled: submitting}}>
{filteredChildren.map((formRow, key) => (
React.cloneElement(formRow, {
key,
Expand Down

0 comments on commit 15f0595

Please sign in to comment.