Created
February 9, 2019 04:15
-
-
Save mwangaben/fe77ad7ed6459b487f47ba8a922e107d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import _ from 'lodash'; | |
class MyForm { | |
constructor(defaults = null) { | |
this.error = {}; | |
this.defaults =defaults | |
if(this.defaults){ | |
Object.assign(this, this.defaults); | |
} | |
} | |
hasError(field) { | |
return this.error.hasOwnProperty(field); | |
} | |
errorOut(field) { | |
let b; | |
_.forEach(this.error, (sms, key) => { | |
if (key === field) { | |
b = sms[0]; | |
} | |
}); | |
return b | |
} | |
clearAll() { | |
return this.error = {} | |
} | |
clear(field) { | |
delete this.error[field]; | |
} | |
any() { | |
return _.isEmpty(this.error); | |
} | |
reset() { | |
let fields = Object.keys(this); | |
_.forEach(fields, (value) => { | |
this[value] = ''; | |
}); | |
return this; | |
} | |
} | |
export default MyForm; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment