@@ -479,25 +479,35 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
479
479
return newAction ;
480
480
}
481
481
482
- private jsonsAreCompatible ( objJson : any , json : any ) : boolean {
483
- let question = this . element ;
484
- if ( ! ! objJson && ! ! objJson . type && question . getType ( ) !== objJson . type ) {
485
- question = QuestionFactory . Instance . createQuestion ( objJson . type , "question" ) || this . element ;
486
- }
482
+ public static checkForNeedDefaultSubitems ( items : QuestionToolboxItem [ ] ) {
483
+ items . filter ( i => i . needDefaultSubitem === undefined ) . forEach ( ( item : QuestionToolboxItem ) => {
484
+ item . needDefaultSubitem = false ;
485
+ if ( item . items ?. length > 0 ) {
486
+ item . needDefaultSubitem = true ;
487
+ item . items . forEach ( subitem => {
488
+ const question = QuestionFactory . Instance . createQuestion ( item . json . type , "question" ) ;
489
+ if ( QuestionAdornerViewModel . jsonsAreCompatible ( question , subitem . json ) ) item . needDefaultSubitem = false ;
490
+ } ) ;
491
+ }
492
+ } ) ;
493
+ }
494
+
495
+ private static jsonsAreCompatible ( element : SurveyElement , json : any ) : boolean {
496
+ let question = element ;
487
497
const keys = Object . keys ( json ) ;
488
498
for ( let i = 0 ; i < keys . length ; i ++ ) {
489
499
const p = keys [ i ] ;
490
- if ( ! objJson && p === "type" ) continue ;
491
- let propertyValue = ! ! objJson ? objJson [ p ] : question . getPropertyValue ( p ) ;
492
- if ( ! ! objJson && propertyValue === undefined ) {
500
+ if ( p === "type" ) continue ;
501
+ let propertyValue = question . getPropertyValue ( p ) ;
502
+ if ( propertyValue === undefined ) {
493
503
propertyValue = p === "type" ? question . getType ( ) : question . getDefaultPropertyValue ( p ) ;
494
504
}
495
505
if ( ! Helpers . isTwoValueEquals ( json [ p ] , propertyValue ) ) return false ;
496
506
}
497
507
return true ;
498
508
}
499
509
private jsonIsCorresponded ( json : any ) {
500
- return this . jsonsAreCompatible ( undefined , json ) ;
510
+ return QuestionAdornerViewModel . jsonsAreCompatible ( this . element , json ) ;
501
511
}
502
512
503
513
private toolboxItemIsCorresponded ( toolboxItem : QuestionToolboxItem , someItemSelectedAlready : boolean ) {
@@ -525,6 +535,7 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
525
535
526
536
protected updateQuestionTypeOrSubtypeListModel ( listModel : ListModel , subtypeOnly : boolean ) {
527
537
const availableItems = this . getConvertToTypes ( ) ;
538
+ QuestionAdornerViewModel . checkForNeedDefaultSubitems ( availableItems ) ;
528
539
const defaultJsons = this . buildDefaultJsonMap ( availableItems ) ;
529
540
const newItems : Array < IAction > = [ ] ;
530
541
let lastItem : QuestionToolboxItem ;
@@ -548,14 +559,12 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
548
559
if ( item . items ?. length > 0 && this . creator . toolbox . showSubitems ) {
549
560
const subactions = [ ] ;
550
561
let selectedSubactionLocal : IAction = undefined ;
551
- let allChildsAreCompatibleToParent = false ;
552
562
item . items . forEach ( subitem => {
553
563
const subaction = toolboxItemToAction ( subitem , ) ;
554
564
if ( this . toolboxItemIsCorresponded ( subitem , ! ! selectedAction ) ) selectedSubactionLocal = subitem ;
555
- if ( this . jsonsAreCompatible ( item . json , subitem . json ) ) allChildsAreCompatibleToParent = true ;
556
565
subactions . push ( subaction ) ;
557
566
} ) ;
558
- if ( ! allChildsAreCompatibleToParent && subactions . length > 0 ) {
567
+ if ( item . needDefaultSubitem && subactions . length > 0 ) {
559
568
const defaultSubaction = toolboxItemToAction ( item ) ;
560
569
defaultSubaction . id = action . id + "-default" ;
561
570
defaultSubaction . iconName = undefined ;
0 commit comments