@@ -76,6 +76,90 @@ exports.default = function (Component) {
7676
7777 var _this = _possibleConstructorReturn ( this , ( WrappedComponent . __proto__ || Object . getPrototypeOf ( WrappedComponent ) ) . call ( this , props ) ) ;
7878
79+ _this . getErrorMessage = function ( ) {
80+ var messages = _this . getErrorMessages ( ) ;
81+ return messages . length ? messages [ 0 ] : null ;
82+ } ;
83+
84+ _this . getErrorMessages = function ( ) {
85+ if ( ! _this . isValid ( ) || _this . showRequired ( ) ) {
86+ return _this . state . externalError || _this . state . validationError || [ ] ;
87+ }
88+ return [ ] ;
89+ } ;
90+
91+ _this . getValue = function ( ) {
92+ return _this . state . value ;
93+ } ;
94+
95+ _this . setValidations = function ( validations , required ) {
96+ // Add validations to the store itself as the props object can not be modified
97+ _this . validations = convertValidationsToObject ( validations ) || { } ;
98+ _this . requiredValidations = required === true ? { isDefaultRequiredValue : true } : convertValidationsToObject ( required ) ;
99+ } ;
100+
101+ _this . setValue = function ( value ) {
102+ var validate = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : true ;
103+
104+ if ( ! validate ) {
105+ _this . setState ( {
106+ value : value
107+ } ) ;
108+ } else {
109+ _this . setState ( {
110+ value : value ,
111+ isPristine : false
112+ } , function ( ) {
113+ _this . context . formsy . validate ( _this ) ;
114+ } ) ;
115+ }
116+ } ;
117+
118+ _this . hasValue = function ( ) {
119+ return _this . state . value !== '' ;
120+ } ;
121+
122+ _this . isFormDisabled = function ( ) {
123+ return _this . context . formsy . isFormDisabled ( ) ;
124+ } ;
125+
126+ _this . isFormSubmitted = function ( ) {
127+ return _this . state . formSubmitted ;
128+ } ;
129+
130+ _this . isPristine = function ( ) {
131+ return _this . state . isPristine ;
132+ } ;
133+
134+ _this . isRequired = function ( ) {
135+ return ! ! _this . props . required ;
136+ } ;
137+
138+ _this . isValid = function ( ) {
139+ return _this . state . isValid ;
140+ } ;
141+
142+ _this . isValidValue = function ( value ) {
143+ return _this . context . formsy . isValidValue . call ( null , _this , value ) ;
144+ } ;
145+
146+ _this . resetValue = function ( ) {
147+ _this . setState ( {
148+ value : _this . state . pristineValue ,
149+ isPristine : true
150+ } , function ( ) {
151+ _this . context . formsy . validate ( _this ) ;
152+ } ) ;
153+ } ;
154+
155+ _this . showError = function ( ) {
156+ return ! _this . showRequired ( ) && ! _this . isValid ( ) ;
157+ } ;
158+
159+ _this . showRequired = function ( ) {
160+ return _this . state . isRequired ;
161+ } ;
162+
79163 _this . state = {
80164 value : props . value ,
81165 isRequired : false ,
@@ -86,22 +170,6 @@ exports.default = function (Component) {
86170 externalError : null ,
87171 formSubmitted : false
88172 } ;
89-
90- _this . getErrorMessage = _this . getErrorMessage . bind ( _this ) ;
91- _this . getErrorMessages = _this . getErrorMessages . bind ( _this ) ;
92- _this . getValue = _this . getValue . bind ( _this ) ;
93- _this . hasValue = _this . hasValue . bind ( _this ) ;
94- _this . isFormDisabled = _this . isFormDisabled . bind ( _this ) ;
95- _this . isPristine = _this . isPristine . bind ( _this ) ;
96- _this . isFormSubmitted = _this . isFormSubmitted . bind ( _this ) ;
97- _this . isRequired = _this . isRequired . bind ( _this ) ;
98- _this . isValidValue = _this . isValidValue . bind ( _this ) ;
99- _this . isValid = _this . isValid . bind ( _this ) ;
100- _this . resetValue = _this . resetValue . bind ( _this ) ;
101- _this . setValidations = _this . setValidations . bind ( _this ) ;
102- _this . setValue = _this . setValue . bind ( _this ) ;
103- _this . showRequired = _this . showRequired . bind ( _this ) ;
104- _this . showError = _this . showError . bind ( _this ) ;
105173 return _this ;
106174 }
107175
@@ -153,111 +221,10 @@ exports.default = function (Component) {
153221 value : function componentWillUnmount ( ) {
154222 this . context . formsy . detachFromForm ( this ) ;
155223 }
156- } , {
157- key : 'getErrorMessage' ,
158- value : function getErrorMessage ( ) {
159- var messages = this . getErrorMessages ( ) ;
160- return messages . length ? messages [ 0 ] : null ;
161- }
162- } , {
163- key : 'getErrorMessages' ,
164- value : function getErrorMessages ( ) {
165- return ! this . isValid ( ) || this . showRequired ( ) ? this . state . externalError || this . state . validationError || [ ] : [ ] ;
166- }
167- } , {
168- key : 'getValue' ,
169- value : function getValue ( ) {
170- return this . state . value ;
171- }
172- } , {
173- key : 'setValidations' ,
174- value : function setValidations ( validations , required ) {
175- // Add validations to the store itself as the props object can not be modified
176- this . validations = convertValidationsToObject ( validations ) || { } ;
177- this . requiredValidations = required === true ? { isDefaultRequiredValue : true } : convertValidationsToObject ( required ) ;
178- }
179224
180225 // By default, we validate after the value has been set.
181226 // A user can override this and pass a second parameter of `false` to skip validation.
182227
183- } , {
184- key : 'setValue' ,
185- value : function setValue ( value ) {
186- var _this3 = this ;
187-
188- var validate = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : true ;
189-
190- if ( ! validate ) {
191- this . setState ( {
192- value : value
193- } ) ;
194- } else {
195- this . setState ( {
196- value : value ,
197- isPristine : false
198- } , function ( ) {
199- _this3 . context . formsy . validate ( _this3 ) ;
200- } ) ;
201- }
202- }
203- } , {
204- key : 'hasValue' ,
205- value : function hasValue ( ) {
206- return this . state . value !== '' ;
207- }
208- } , {
209- key : 'isFormDisabled' ,
210- value : function isFormDisabled ( ) {
211- return this . context . formsy . isFormDisabled ( ) ;
212- }
213- } , {
214- key : 'isFormSubmitted' ,
215- value : function isFormSubmitted ( ) {
216- return this . state . formSubmitted ;
217- }
218- } , {
219- key : 'isPristine' ,
220- value : function isPristine ( ) {
221- return this . state . isPristine ;
222- }
223- } , {
224- key : 'isRequired' ,
225- value : function isRequired ( ) {
226- return ! ! this . props . required ;
227- }
228- } , {
229- key : 'isValid' ,
230- value : function isValid ( ) {
231- return this . state . isValid ;
232- }
233- } , {
234- key : 'isValidValue' ,
235- value : function isValidValue ( value ) {
236- return this . context . formsy . isValidValue . call ( null , this , value ) ;
237- // return this.props.isValidValue.call(null, this, value);
238- }
239- } , {
240- key : 'resetValue' ,
241- value : function resetValue ( ) {
242- var _this4 = this ;
243-
244- this . setState ( {
245- value : this . state . pristineValue ,
246- isPristine : true
247- } , function ( ) {
248- _this4 . context . formsy . validate ( _this4 ) ;
249- } ) ;
250- }
251- } , {
252- key : 'showError' ,
253- value : function showError ( ) {
254- return ! this . showRequired ( ) && ! this . isValid ( ) ;
255- }
256- } , {
257- key : 'showRequired' ,
258- value : function showRequired ( ) {
259- return this . state . isRequired ;
260- }
261228 } , {
262229 key : 'render' ,
263230 value : function render ( ) {
0 commit comments