@@ -4154,20 +4154,28 @@ export class SurveyCreatorModel extends Base
4154
4154
public get addNewQuestionText ( ) {
4155
4155
return this . getAddNewQuestionText ( ) ;
4156
4156
}
4157
+ public isAllowedNestingLevel ( element : SurveyElement , childNesting = 0 ) : boolean {
4158
+ if ( ! element ) return true ;
4159
+ return this . maxNestingLevel < 0 || this . maxNestingLevel >= childNesting + SurveyHelper . getElementParentContainers ( element ) . length ;
4160
+ }
4161
+ public isAllowedNestedPanels ( element : SurveyElement , childNesting = 0 ) : boolean {
4162
+ if ( ! element ) return true ;
4163
+ return this . maxNestedPanels < 0 || this . maxNestedPanels >= childNesting + SurveyHelper . getElementDeepLength ( element ) ;
4164
+ }
4157
4165
public getAvailableToolboxItems ( element ?: SurveyElement , isAddNew : boolean = true ) : Array < QuestionToolboxItem > {
4158
4166
const res : Array < QuestionToolboxItem > = [ ] ;
4159
4167
this . toolbox . items . forEach ( ( item ) => { if ( ! item . showInToolboxOnly ) res . push ( item ) ; } ) ;
4160
4168
4161
4169
if ( ! element ) return res ;
4162
4170
if ( ! isAddNew && ( element . isPanel || SurveyHelper . isPanelDynamic ( element ) ) ) return res ;
4163
4171
4164
- if ( this . maxNestingLevel >= 0 && this . maxNestingLevel < SurveyHelper . getElementParentContainers ( element ) . length ) {
4172
+ if ( ! this . isAllowedNestingLevel ( element ) ) {
4165
4173
for ( let i = res . length - 1 ; i >= 0 ; i -- ) {
4166
4174
if ( res [ i ] . isPanel || Serializer . isDescendantOf ( res [ i ] . typeName , "paneldynamic" ) ) {
4167
4175
res . splice ( i , 1 ) ;
4168
4176
}
4169
4177
}
4170
- } else if ( this . maxNestedPanels >= 0 && this . maxNestedPanels < SurveyHelper . getElementDeepLength ( element ) ) {
4178
+ } else if ( ! this . isAllowedNestedPanels ( element ) ) {
4171
4179
for ( let i = res . length - 1 ; i >= 0 ; i -- ) {
4172
4180
if ( res [ i ] . isPanel ) {
4173
4181
res . splice ( i , 1 ) ;
0 commit comments