File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ module.exports = function (Component) {
1212 setValue : this . setValue ,
1313 resetValue : this . resetValue ,
1414 getValue : this . getValue ,
15+ updateValue : this . updateValue ,
1516 hasValue : this . hasValue ,
1617 getErrorMessage : this . getErrorMessage ,
1718 getErrorMessages : this . getErrorMessages ,
Original file line number Diff line number Diff line change @@ -124,6 +124,17 @@ module.exports = {
124124 //this.props._validate(this);
125125 } . bind ( this ) ) ;
126126 } ,
127+ // update the value, along with its pristineValue and pristineFlag
128+ updateValue : function ( value ) {
129+ this . setState ( {
130+ _value : value ,
131+ _isPristine : true ,
132+ _pristineValue : value
133+ } , function ( ) {
134+ this . context . formsy . validate ( this ) ;
135+ //this.props._validate(this);
136+ } . bind ( this ) ) ;
137+ } ,
127138 resetValue : function ( ) {
128139 this . setState ( {
129140 _value : this . state . _pristineValue ,
Original file line number Diff line number Diff line change @@ -97,6 +97,12 @@ Formsy.Form = React.createClass({
9797 this . resetModel ( data ) ;
9898 } ,
9999
100+ // updates all inputs and their _pristineValues to specified data
101+ update : function ( data ) {
102+ this . setFormPristine ( true ) ;
103+ this . updateModel ( data ) ;
104+ } ,
105+
100106 // Update model, submit to url prop and send the model
101107 submit : function ( event ) {
102108
@@ -150,6 +156,19 @@ Formsy.Form = React.createClass({
150156 this . validateForm ( ) ;
151157 } ,
152158
159+ // Update each key in the model to the specified value
160+ updateModel : function ( data ) {
161+ this . inputs . forEach ( component => {
162+ var name = component . props . name ;
163+ if ( data && data . hasOwnProperty ( name ) ) {
164+ component . updateValue ( data [ name ] ) ;
165+ } else {
166+ component . resetValue ( ) ;
167+ }
168+ } ) ;
169+ this . validateForm ( ) ;
170+ } ,
171+
153172 setInputValidationErrors : function ( errors ) {
154173 this . inputs . forEach ( component => {
155174 var name = component . props . name ;
@@ -433,6 +452,7 @@ Formsy.Form = React.createClass({
433452 onInvalidSubmit,
434453 onChange,
435454 reset,
455+ update,
436456 preventExternalInvalidation,
437457 onSuccess,
438458 onError,
You can’t perform that action at this time.
0 commit comments