@@ -733,8 +733,9 @@ export class Question extends SurveyElement<Question>
733
733
}
734
734
const questions = this . getSingleInputQuestions ( ) ;
735
735
if ( Array . isArray ( questions ) && questions . length > 0 ) {
736
- questions [ 0 ] . onFirstRendering ( ) ;
737
- return questions [ 0 ] ;
736
+ const q = questions [ 0 ] ;
737
+ this . onBeforeSetSingleInputQuestion ( q ) ;
738
+ return q ;
738
739
}
739
740
return undefined ;
740
741
}
@@ -798,8 +799,10 @@ export class Question extends SurveyElement<Question>
798
799
this . onSingleInputChanged ( ) ;
799
800
}
800
801
}
801
- private onSingleInputChanged ( ) : void {
802
- this . resetSingleInputSummary ( ) ;
802
+ private onSingleInputChanged ( resetSummary : boolean = true ) : void {
803
+ if ( resetSummary ) {
804
+ this . resetSingleInputSummary ( ) ;
805
+ }
803
806
this . singleInputLocTitle ?. strChanged ( ) ;
804
807
this . resetPropertyValue ( "singleInputLocTitle" ) ;
805
808
this . calcSingleInputActions ( ) ;
@@ -812,9 +815,20 @@ export class Question extends SurveyElement<Question>
812
815
public validateSingleInput ( fireCallback : boolean = true , rec : any = null ) : boolean {
813
816
const q = this . currentSingleInputQuestion ;
814
817
if ( ! q ) return true ;
815
- return q . validate ( fireCallback , rec ) ;
818
+ rec = rec || {
819
+ fireCallback : fireCallback ,
820
+ focusOnFirstError : fireCallback ,
821
+ firstErrorQuestion : < any > null ,
822
+ result : false ,
823
+ } ;
824
+ const res = q . validate ( fireCallback , rec ) ;
825
+ if ( ! res && rec . focusOnFirstError && ! ! rec . firstErrorQuestion ) {
826
+ rec . firstErrorQuestion . focus ( true ) ;
827
+ }
828
+ return res ;
816
829
}
817
830
public getSingleInputElementPos ( ) : number {
831
+ if ( this . singleInputQuestion === this ) return 0 ;
818
832
const pQ = this . currentSingleInputParentQuestion ;
819
833
if ( pQ !== this ) {
820
834
let res = pQ . getSingleInputElementPos ( ) ;
@@ -859,7 +873,9 @@ export class Question extends SurveyElement<Question>
859
873
this . resetSingleInput ( ) ;
860
874
}
861
875
}
876
+ private isSingleInputSummaryShown : boolean ;
862
877
public onSetAsSingleInput ( ) : void {
878
+ this . isSingleInputSummaryShown = false ;
863
879
const needReset = ! this . wasRendered || this . singleInputSummary ;
864
880
this . onFirstRendering ( ) ;
865
881
if ( needReset ) {
@@ -941,7 +957,7 @@ export class Question extends SurveyElement<Question>
941
957
private getSingleQuestionActions ( ) : Array < Action > {
942
958
const res = new Array < Action > ( ) ;
943
959
const p = this . currentSingleInputParentQuestion ;
944
- if ( ! p ) return res ;
960
+ if ( ! p || p === this ) return res ;
945
961
const pSQs = p . getSingleInputQuestions ( ) ;
946
962
const qs = new Array < Question > ( ) ;
947
963
let summaryQ = undefined ;
@@ -956,21 +972,27 @@ export class Question extends SurveyElement<Question>
956
972
}
957
973
for ( let i = qs . length - 1 ; i >= 0 ; i -- ) {
958
974
const q = qs [ i ] ;
959
- const title = q == summaryQ ? q . locTitle : q . singleInputLocTitle ;
960
- const action = new Action ( { id : "single-action" + q . id , locTitle : title ,
961
- css : this . cssClasses . breadcrumbsItem ,
962
- innerCss : this . cssClasses . breadcrumbsItemButton ,
963
- action : ( ) => {
964
- if ( q == summaryQ ) {
965
- q . setSingleInputQuestion ( q ) ;
966
- } else {
975
+ if ( q !== summaryQ ) {
976
+ //const title = q == summaryQ ? q.locTitle : q.singleInputLocTitle;
977
+ const title = q . singleInputLocTitle ;
978
+ const action = new Action ( { id : "single-action" + q . id , locTitle : title ,
979
+ css : this . cssClasses . breadcrumbsItem ,
980
+ innerCss : this . cssClasses . breadcrumbsItemButton ,
981
+ action : ( ) => {
967
982
q . singleInputMoveToFirst ( ) ;
983
+ /*
984
+ if (q == summaryQ) {
985
+ q.setSingleInputQuestion(q);
986
+ } else {
987
+ q.singleInputMoveToFirst();
988
+ }
989
+ */
968
990
}
969
- }
970
- } ) ;
991
+ } ) ;
971
992
972
- action . cssClasses = { } ;
973
- res . push ( action ) ;
993
+ action . cssClasses = { } ;
994
+ res . push ( action ) ;
995
+ }
974
996
}
975
997
return res ;
976
998
}
@@ -993,23 +1015,25 @@ export class Question extends SurveyElement<Question>
993
1015
}
994
1016
private getSingleInputQuestions ( ) : Array < Question > {
995
1017
if ( ! this . supportNestedSingleInput ( ) ) return [ ] ;
996
- const res = this . getSingleInputQuestionsCore ( this . getPropertyValue ( "singleInputQuestion" ) ) ;
1018
+ const question = this . getPropertyValue ( "singleInputQuestion" ) ;
1019
+ if ( question === this ) return [ this ] ;
1020
+ const res = this . getSingleInputQuestionsCore ( question , ! question || ! this . isSingleInputSummaryShown ) ;
997
1021
res . forEach ( q => { if ( q !== this ) this . onSingleInputQuestionAdded ( q ) ; } ) ;
998
1022
return res ;
999
1023
}
1000
- protected getSingleInputQuestionsCore ( question : Question ) : Array < Question > {
1024
+ protected getSingleInputQuestionsCore ( question : Question , checkDynamic : boolean ) : Array < Question > {
1001
1025
return this . getNestedQuestions ( true , false ) ;
1002
1026
}
1003
1027
protected onSingleInputQuestionAdded ( question : Question ) : void { }
1004
1028
protected fillSingleInputQuestionsInContainer ( res : Array < Question > , innerQuestion : Question ) : void { }
1005
- protected getSingleInputQuestionsForDynamic ( question ? : Question ) : Array < Question > {
1029
+ protected getSingleInputQuestionsForDynamic ( question : Question , arr : Array < Question > ) : Array < Question > {
1006
1030
const res = new Array < Question > ( ) ;
1007
- if ( question ) {
1008
- this . setSingleInputQuestionCore ( question ) ;
1031
+ if ( ! ! question && question !== this && arr . indexOf ( question ) < 0 ) {
1032
+ this . fillSingleInputQuestionsInContainer ( res , question ) ;
1009
1033
}
1010
- const q = this . getPropertyValue ( "singleInputQuestion" ) ;
1011
- if ( ! ! q && q !== this ) {
1012
- this . fillSingleInputQuestionsInContainer ( res , q ) ;
1034
+ arr . forEach ( q => res . push ( q ) ) ;
1035
+ if ( this . isSingleInputSummaryShown && res . length > 0 ) {
1036
+ res . unshift ( this ) ;
1013
1037
}
1014
1038
res . push ( this ) ;
1015
1039
return res ;
@@ -1018,13 +1042,19 @@ export class Question extends SurveyElement<Question>
1018
1042
protected singleInputAddItemCore ( ) : void { }
1019
1043
protected singleInputRemoveItemCore ( question : Question ) : void { }
1020
1044
private setSingleInputQuestionCore ( question : Question ) : void {
1021
- question . onFirstRendering ( ) ;
1045
+ this . onBeforeSetSingleInputQuestion ( question ) ;
1022
1046
this . setPropertyValue ( "singleInputQuestion" , question ) ;
1023
1047
}
1024
- protected setSingleInputQuestion ( question : Question ) : void {
1048
+ private onBeforeSetSingleInputQuestion ( question : Question ) : void {
1049
+ question . onFirstRendering ( ) ;
1050
+ if ( question === this ) {
1051
+ this . isSingleInputSummaryShown = true ;
1052
+ }
1053
+ }
1054
+ protected setSingleInputQuestion ( question : Question , onPrev ?: boolean ) : void {
1025
1055
if ( this . singleInputQuestion !== question ) {
1026
1056
this . setSingleInputQuestionCore ( question ) ;
1027
- this . onSingleInputChanged ( ) ;
1057
+ this . onSingleInputChanged ( ! onPrev || question !== this ) ;
1028
1058
}
1029
1059
}
1030
1060
private nextPrevSingleInput ( skip : number ) : boolean {
@@ -1045,7 +1075,7 @@ export class Question extends SurveyElement<Question>
1045
1075
}
1046
1076
index += skip ;
1047
1077
if ( index < 0 || index >= questions . length ) return false ;
1048
- this . setSingleInputQuestion ( questions [ index ] ) ;
1078
+ this . setSingleInputQuestion ( questions [ index ] , skip < 0 ) ;
1049
1079
return true ;
1050
1080
}
1051
1081
/**
0 commit comments