Skip to content

Commit

Permalink
Fix eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
rkuykendall committed Nov 10, 2017
1 parent 08efd36 commit 9f12b30
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 70 deletions.
48 changes: 24 additions & 24 deletions src/Wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,30 @@ export default (Component) => {
return this.state.value;
}

setValidations(validations, required) {
// Add validations to the store itself as the props object can not be modified
this.validations = convertValidationsToObject(validations) || {};
this.requiredValidations = required === true ? { isDefaultRequiredValue: true } :
convertValidationsToObject(required);
}

// By default, we validate after the value has been set.
// A user can override this and pass a second parameter of `false` to skip validation.
setValue(value, validate = true) {
if (!validate) {
this.setState({
value,
});
} else {
this.setState({
value,
isPristine: false,
}, () => {
this.context.formsy.validate(this);
});
}
}

hasValue() {
return this.state.value !== '';
}
Expand Down Expand Up @@ -165,30 +189,6 @@ export default (Component) => {
});
}

setValidations(validations, required) {
// Add validations to the store itself as the props object can not be modified
this.validations = convertValidationsToObject(validations) || {};
this.requiredValidations = required === true ? { isDefaultRequiredValue: true } :
convertValidationsToObject(required);
}

// By default, we validate after the value has been set.
// A user can override this and pass a second parameter of `false` to skip validation.
setValue(value, validate = true) {
if (!validate) {
this.setState({
value,
});
} else {
this.setState({
value,
isPristine: false,
}, () => {
this.context.formsy.validate(this);
});
}
}

showError() {
return !this.showRequired() && !this.isValid();
}
Expand Down
92 changes: 46 additions & 46 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,6 @@ class Formsy extends React.Component {
}
}

// Method put on each input component to register
// itself to the form
attachToForm(component) {
if (this.inputs.indexOf(component) === -1) {
this.inputs.push(component);
}

this.validate(component);
}

// Method put on each input component to unregister
// itself from the form
detachFromForm(component) {
const componentPos = this.inputs.indexOf(component);

if (componentPos !== -1) {
this.inputs = this.inputs.slice(0, componentPos).concat(this.inputs.slice(componentPos + 1));
}

this.validateForm();
}

getCurrentValues() {
return this.inputs.reduce((data, component) => {
const name = component.props.name;
Expand All @@ -108,9 +86,30 @@ class Formsy extends React.Component {
}, {});
}

// Checks if the values have changed from their initial value
isChanged() {
return !utils.isSame(this.getPristineValues(), this.getCurrentValues());
setFormPristine(isPristine) {
this.setState({
formSubmitted: !isPristine,
});

// Iterate through each component and set it as pristine
// or "dirty".
this.inputs.forEach((component) => {
component.setState({
formSubmitted: !isPristine,
isPristine,
});
});
}

setInputValidationErrors(errors) {
this.inputs.forEach((component) => {
const name = component.props.name;
const args = [{
isValid: !(name in errors),
validationError: typeof errors[name] === 'string' ? [errors[name]] : errors[name],
}];
component.setState(...args);
});
}

isFormDisabled() {
Expand Down Expand Up @@ -210,30 +209,31 @@ class Formsy extends React.Component {
};
}

setInputValidationErrors(errors) {
this.inputs.forEach((component) => {
const name = component.props.name;
const args = [{
isValid: !(name in errors),
validationError: typeof errors[name] === 'string' ? [errors[name]] : errors[name],
}];
component.setState(...args);
});
// Method put on each input component to register
// itself to the form
attachToForm(component) {
if (this.inputs.indexOf(component) === -1) {
this.inputs.push(component);
}

this.validate(component);
}

setFormPristine(isPristine) {
this.setState({
formSubmitted: !isPristine,
});
// Method put on each input component to unregister
// itself from the form
detachFromForm(component) {
const componentPos = this.inputs.indexOf(component);

// Iterate through each component and set it as pristine
// or "dirty".
this.inputs.forEach((component) => {
component.setState({
formSubmitted: !isPristine,
isPristine,
});
});
if (componentPos !== -1) {
this.inputs = this.inputs.slice(0, componentPos).concat(this.inputs.slice(componentPos + 1));
}

this.validateForm();
}

// Checks if the values have changed from their initial value
isChanged() {
return !utils.isSame(this.getPristineValues(), this.getCurrentValues());
}

// Update model, submit to url prop and send the model
Expand Down

0 comments on commit 9f12b30

Please sign in to comment.