File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
primitives/filed-form /src/form-core Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -774,7 +774,7 @@ class FormStore {
774774 } ) ;
775775 } ;
776776
777- validateFields = async ( names ?: NamePath [ ] , opts ?: ValidateFieldsOptions ) => {
777+ private validateFields = async ( names ?: NamePath [ ] , opts ?: ValidateFieldsOptions ) => {
778778 let list : string [ ] ;
779779
780780 if ( names && names . length > 0 ) {
@@ -807,7 +807,7 @@ class FormStore {
807807 }
808808 } ) ;
809809
810- const results = await Promise . all ( list . map ( n => this . validateField ( n , opts ) ) ) ;
810+ const results = await this . transactionAsync ( ( ) => Promise . all ( list . map ( n => this . validateField ( n , opts ) ) ) ) ;
811811
812812 return results . every ( Boolean ) ;
813813 } ;
@@ -852,6 +852,18 @@ class FormStore {
852852 }
853853 } ;
854854
855+ private async transactionAsync < T > ( fn : ( ) => Promise < T > ) : Promise < T > {
856+ this . begin ( ) ;
857+ try {
858+ return await fn ( ) ;
859+ } catch ( e ) {
860+ this . rollback ( ) ;
861+ throw e ;
862+ } finally {
863+ this . commit ( ) ;
864+ }
865+ }
866+
855867 // ===== Array Operation =====
856868 private arrayOp = ( name : NamePath , op : 'insert' | 'move' | 'remove' | 'replace' | 'swap' , args : any ) => {
857869 const arr = this . getFieldValue ( name ) ;
You can’t perform that action at this time.
0 commit comments