Skip to content

Commit

Permalink
Introduce "set" Property Editor for selecting several values from array
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Apr 5, 2019
1 parent c12850a commit a53c4f3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/entries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export {
export {
SurveyPropertyDefaultValueEditor,
SurveyPropertyDefaultRowValueEditor,
SurveyPropertyDefaultPanelValueEditor
SurveyPropertyDefaultPanelValueEditor,
SurveyPropertySetEditor
} from "../propertyEditors/propertyDefaultValueEditor";
export {
SurveyPropertyTriggersEditor
Expand Down
37 changes: 34 additions & 3 deletions src/propertyEditors/propertyDefaultValueEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ export class SurveyPropertyDefaultValueEditor extends SurveyPropertyModalEditor
SurveyPropertyDefaultValueEditor.defaultQuestionName
);
}
private getJsonType(type: string): string {
return type != "expression" ? type : "text";
}
}

export class SurveyPropertyDefaultRowValueEditorBase extends SurveyPropertyDefaultValueEditor {
Expand Down Expand Up @@ -139,6 +136,34 @@ export class SurveyPropertyDefaultPanelValueEditor extends SurveyPropertyDefault
}
}

export class SurveyPropertySetEditor extends SurveyPropertyDefaultValueEditor {
constructor(property: Survey.JsonObjectProperty) {
super(property);
}
public get editorType(): string {
return "set";
}
public get editorTypeTemplate(): string {
return "value";
}
protected getSurveyInitialValue(): any {
var res = this.editingValue;
if (!res) return res;
if (!Array.isArray(res)) {
res = [res];
}
return res;
}
protected buildQuestionJson(): any {
var question = new Survey.QuestionCheckbox("q1");
question.hasSelectAll = true;
if (!!this.property) {
question.choices = this.property.getChoices(this.object);
}
return SurveyPropertyDefaultValueEditor.createJsonFromQuestion(question);
}
}

SurveyPropertyEditorFactory.registerEditor("value", function(
property: Survey.JsonObjectProperty
): SurveyPropertyEditorBase {
Expand All @@ -156,3 +181,9 @@ SurveyPropertyEditorFactory.registerEditor("panelvalue", function(
): SurveyPropertyEditorBase {
return new SurveyPropertyDefaultPanelValueEditor(property);
});

SurveyPropertyEditorFactory.registerEditor("set", function(
property: Survey.JsonObjectProperty
): SurveyPropertyEditorBase {
return new SurveyPropertySetEditor(property);
});

0 comments on commit a53c4f3

Please sign in to comment.