99 */
1010import {
1111 AbortKeyStroke , App , aria , AriaLabelledByInsertPosition , arrays , BusyIndicatorOptions , Button , ButtonSystemType , ChildModelOf , DialogLayout , DisabledStyle , DisplayParent , DisplayViewId , EnumObject , ErrorHandler , Event , EventHandler ,
12- FileChooser , FileChooserController , FocusRule , FormController , FormEventMap , FormField , FormGrid , FormInvalidEvent , FormLayout , FormLifecycle , FormModel , FormRevealInvalidFieldEvent , GlassPaneRenderer , GroupBox , HtmlComponent ,
13- InitModelOf , KeyStroke , KeyStrokeContext , Lifecycle , MessageBox , MessageBoxController , MessageBoxes , ModelOf , NotificationBadgeStatus , ObjectOrChildModel , objects , Point , PopupWindow , PropertyChangeEvent , Rectangle , scout , Status ,
14- StatusOrModel , strings , TextListWithTitle , tooltips , TreeVisitResult , ValidationResult , webstorage , Widget , WrappedFormField
12+ FileChooser , FileChooserController , FocusRule , FormController , FormEventMap , FormGrid , FormInvalidEvent , FormLayout , FormLifecycle , FormModel , FormRevealInvalidFieldEvent , GlassPaneRenderer , GroupBox , HtmlComponent , InitModelOf ,
13+ KeyStroke , KeyStrokeContext , Lifecycle , MessageBox , MessageBoxController , MessageBoxes , ModelOf , NotificationBadgeStatus , ObjectOrChildModel , objects , Point , PopupWindow , PropertyChangeEvent , Rectangle , scout , Status , StatusOrModel ,
14+ strings , TextListWithTitle , tooltips , TreeVisitResult , ValidationResult , webstorage , Widget , WrappedFormField
1515} from '../index' ;
1616import $ from 'jquery' ;
1717
@@ -449,17 +449,23 @@ export class Form extends Widget implements FormModel, DisplayParent {
449449 try {
450450 this . _setFormLoading ( true ) ;
451451 return this . _load ( )
452- . then ( async data => {
452+ . then ( data => {
453453 if ( this . destroyed ) {
454454 // If form has been closed right after it was opened ignore the load result
455455 return ;
456456 }
457+
457458 this . setData ( data ) ;
458459 this . importData ( ) ;
459- await this . _whenPendingFieldsReady ( ) ;
460- this . _setFormLoading ( false ) ;
461- this . formLoaded = true ;
462- this . trigger ( 'load' ) ;
460+
461+ // Wait for async field validators to complete so the value is set when the form loading finishes
462+ let pendingFields = FormLifecycle . validateFormFields ( this ) . pendingElements ;
463+ if ( pendingFields . length ) {
464+ return $ . promiseAll ( pendingFields . map ( field => field . promise ) )
465+ . then ( ( ) => this . _loadingDone ( ) ) ;
466+ }
467+
468+ this . _loadingDone ( ) ;
463469 } )
464470 . always ( ( ) => this . _setFormLoading ( false ) ) ;
465471 } catch ( error ) {
@@ -468,23 +474,14 @@ export class Form extends Widget implements FormModel, DisplayParent {
468474 }
469475 }
470476
471- protected _setFormLoading ( loading : boolean ) {
472- this . _setProperty ( 'formLoading' , loading ) ;
477+ protected _loadingDone ( ) {
478+ this . _setFormLoading ( false ) ;
479+ this . formLoaded = true ;
480+ this . trigger ( 'load' ) ;
473481 }
474482
475- protected _whenPendingFieldsReady ( ) {
476- let promises = [ ] ;
477- this . visitFields ( ( field : FormField ) => {
478- let result = field . getValidationResult ( ) ;
479- if ( result . promise ) {
480- promises . push ( result . promise ) ;
481- }
482- if ( field . lifecycleBoundary ) {
483- return TreeVisitResult . SKIP_SUBTREE ;
484- }
485- return result . visitResult ;
486- } ) ;
487- return $ . promiseAll ( promises ) ;
483+ protected _setFormLoading ( loading : boolean ) {
484+ this . _setProperty ( 'formLoading' , loading ) ;
488485 }
489486
490487 /**
0 commit comments