Skip to content

Commit

Permalink
QuestionBoolean, fix a bug with defaultValue on loading from JSON: su…
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Aug 31, 2017
1 parent 6281a5f commit c7daca3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/knockout/koquestion_boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export class QuestionBooleanImplementor extends QuestionImplementor {
protected setkoValue(newValue: any) {
super.setkoValue(newValue);
this.koIndeterminate((<QuestionBoolean>this.question).isIndeterminate);
if(this.koCheckedValue() != (<QuestionBoolean>this.question).checkedValue) {
this.koCheckedValue((<QuestionBoolean>this.question).checkedValue);
}
}
protected updateCheckedValue(newValue: any) {
(<QuestionBoolean>this.question).checkedValue = newValue;
Expand Down
12 changes: 9 additions & 3 deletions src/question_boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export class QuestionBooleanModel extends Question {
super.onSetData();
this.updateValueWithDefaults();
}
public onSurveyLoad() {
super.onSurveyLoad();
this.updateValueWithDefaults();
}
/**
* Get/set question value in 3 modes: indeterminate (value is empty), true (check is set) and false (check is unset).
* @see valueTrue
Expand Down Expand Up @@ -81,9 +85,11 @@ export class QuestionBooleanModel extends Question {
private getValueTrue(): any { return this.valueTrue ? this.valueTrue : true; }
private getValueFalse(): any { return this.valueFalse ? this.valueFalse : false; }
private updateValueWithDefaults() {
if(!this.isEmpty()) return;
if(this.defaultValue == "true") this.value = this.getValueTrue();
else if(this.defaultValue == "false") this.value = this.getValueFalse();
if(this.isLoadingFromJson) return;
if(!this.isEmpty() && !this.isDesignMode) return;
if(this.defaultValue == "true") this.checkedValue = true;
if(this.defaultValue == "false") this.checkedValue = false;
if(this.defaultValue == "indeterminate") this.value = null;
}
}

Expand Down

0 comments on commit c7daca3

Please sign in to comment.