@@ -22,6 +22,7 @@ import { LocalizableString } from "./localizablestring";
22
22
import { SurveyError } from "./survey-error" ;
23
23
import { CustomError } from "./error" ;
24
24
import { ConsoleWarnings } from "./console-warnings" ;
25
+ import { settings } from "./settings" ;
25
26
26
27
/**
27
28
* An interface used to create custom question types.
@@ -1244,6 +1245,31 @@ export class QuestionCompositeModel extends QuestionCustomModelBase {
1244
1245
this . settingNewValue = false ;
1245
1246
this . runPanelTriggers ( QuestionCompositeModel . ItemVariableName + "." + name , newValue ) ;
1246
1247
}
1248
+ setComment ( name : string , newValue : string , locNotification : any ) : any {
1249
+ let val = this . getUnbindValue ( this . value ) ;
1250
+ const commentName = this . getCommentName ( name ) ;
1251
+ if ( ! val && ! newValue || ! ! newValue && ! ! val && val [ commentName ] === newValue ) return ;
1252
+ if ( ! ! newValue ) {
1253
+ if ( ! val ) { val = { } ; }
1254
+ val [ commentName ] = newValue ;
1255
+ } else {
1256
+ delete val [ commentName ] ;
1257
+ }
1258
+ const q = < Question > this . getQuestionByName ( name ) ;
1259
+ if ( ! ! q && q . comment !== newValue ) {
1260
+ q . comment = newValue ;
1261
+ }
1262
+ this . value = val ;
1263
+ }
1264
+ getComment ( name : string ) : string {
1265
+ const q = < Question > this . getQuestionByName ( name ) ;
1266
+ if ( ! ! q ) return q . comment ;
1267
+ const val = this . value ;
1268
+ return ! ! val && val [ this . getCommentName ( name ) ] || "" ;
1269
+ }
1270
+ private getCommentName ( name : string ) : string {
1271
+ return name + settings . commentSuffix ;
1272
+ }
1247
1273
private runPanelTriggers ( name : string , value : any ) : void {
1248
1274
if ( ! ! this . contentPanel ) {
1249
1275
this . contentPanel . questions . forEach ( q => {
@@ -1321,18 +1347,23 @@ export class QuestionCompositeModel extends QuestionCustomModelBase {
1321
1347
super . setQuestionValue ( newValue , updateIsAnswered ) ;
1322
1348
}
1323
1349
private setValuesIntoQuestions ( newValue : any ) : void {
1324
- if ( ! this . contentPanel ) return ;
1350
+ if ( ! this . contentPanel || this . settingNewValue ) return ;
1325
1351
newValue = this . getValueForContentPanel ( newValue ) ;
1326
1352
const oldSettingNewValue = this . settingNewValue ;
1327
1353
this . settingNewValue = true ;
1328
1354
const questions = this . contentPanel . questions ;
1329
1355
for ( var i = 0 ; i < questions . length ; i ++ ) {
1330
- const key = questions [ i ] . getValueName ( ) ;
1331
- const val = ! ! newValue ? newValue [ key ] : undefined ;
1332
1356
const q = questions [ i ] ;
1357
+ const key = q . getValueName ( ) ;
1358
+ const commentKey = this . getCommentName ( key ) ;
1359
+ const val = ! ! newValue ? newValue [ key ] : undefined ;
1360
+ const commentVal = ! ! newValue && newValue [ commentKey ] || "" ;
1333
1361
if ( ! this . isTwoValueEquals ( q . value , val ) && ( val !== undefined || ! q . isEmpty ( ) ) ) {
1334
1362
q . value = val ;
1335
1363
}
1364
+ if ( q . comment !== commentVal ) {
1365
+ q . comment = commentVal ;
1366
+ }
1336
1367
}
1337
1368
this . settingNewValue = oldSettingNewValue ;
1338
1369
}
0 commit comments