Skip to content

Commit

Permalink
resolve #5365 Property Grid - It should be possible to change the loc…
Browse files Browse the repository at this point in the history
…alization of the None option within Input mask type drop-down (#5368)

Co-authored-by: OlgaLarina <olga.larina.dev@gmail.com>
  • Loading branch information
OlgaLarina and OlgaLarina committed Mar 29, 2024
1 parent 695c966 commit 739997f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/survey-creator-core/src/localization/english.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ export var enStrings = {
textUpdateMode: "Update input field values",
maskType: "Input mask type",
maskTypes: {
none: "None",
patternmask: "Pattern",
numericmask: "Numeric",
datetimemask: "Date and Time",
Expand Down
12 changes: 6 additions & 6 deletions packages/survey-creator-core/src/property-grid/maskSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,22 @@ export class PropertyGridEditorQuestionMaskSettings extends PropertyGridEditor {
PropertyGridEditorCollection.register(new PropertyGridEditorQuestionMaskSettings());

export class PropertyGridEditorMaskType extends PropertyGridEditor {
private _noneItem = { value: "none", text: getLocString("pv.none") };

public fit(prop: JsonObjectProperty): boolean {
return prop.type == "masktype";
}
public getJSON(obj: Base, prop: JsonObjectProperty, options: ISurveyCreatorOptions): any {
const noneItemValue = "none";
const result = {
type: "dropdown",
// optionsCaption: editorLocalization.getString("pe.conditionSelectQuestion"),
default: this._noneItem.value,
default: noneItemValue,
allowClear: false,
searchEnabled: false,
choices: this.getChoices(obj, prop, options)
choices: this.getChoices(noneItemValue)
};
return result;
}
private getChoices(obj: Base, prop: JsonObjectProperty, options: ISurveyCreatorOptions): Array<any> {
private getChoices(noneItemValue: string): Array<any> {
const classes = Serializer.getChildrenClasses("masksettings") || [];
const choices = classes.map((cl: JsonMetadataClass) => {
let value = cl.name;
Expand All @@ -90,7 +89,8 @@ export class PropertyGridEditorMaskType extends PropertyGridEditor {
}
return { value: value, text: getLocString("pe.maskTypes." + cl.name) };
});
choices.splice(0, 0, this._noneItem);
const noneItem = { value: noneItemValue, text: getLocString("pe.maskTypes.none") };
choices.splice(0, 0, noneItem);
return choices;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from "../../src/property-grid/matrices";
export * from "../../src/property-grid/bindings";
export * from "../../src/property-grid/condition";
export * from "../../src/property-grid/restfull";
export * from "../../src/property-grid/maskSettings";
export * from "../../src/custom-questions/question-text-with-reset";
export * from "../../src/components/link-value";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3241,3 +3241,29 @@ test("Check enableIf for nested proeprties", () => {

prop.enableIf = oldEnableIf;
});
test("PropertyGridEditorMaskType editor", () => {
const question = new QuestionTextModel("q1");
const propertyGrid = new PropertyGridModelTester(question);
const maskTypeQuestion = propertyGrid.survey.getQuestionByName("maskType");
expect(maskTypeQuestion.getType()).toEqual("dropdown");
expect(maskTypeQuestion.selectedItem.value).toEqual("none");
expect(maskTypeQuestion.selectedItem.title).toEqual("None");

maskTypeQuestion.value = "pattern";
expect(maskTypeQuestion.selectedItem.value).toEqual("pattern");
expect(maskTypeQuestion.selectedItem.title).toEqual("Pattern");
});
test("PropertyGridEditorMaskType editor: localize item", () => {
const enLocale = editorLocalization.getLocale("");
const oldMaskTypesNone = enLocale.pe.maskTypes.none;
enLocale.pe.maskTypes.none = "Unmasked";

const question = new QuestionTextModel("q1");
const propertyGrid = new PropertyGridModelTester(question);
const maskTypeQuestion = propertyGrid.survey.getQuestionByName("maskType");
expect(maskTypeQuestion.getType()).toEqual("dropdown");
expect(maskTypeQuestion.selectedItem.value).toEqual("none");
expect(maskTypeQuestion.selectedItem.title).toEqual("Unmasked");

enLocale.pe.maskTypes.none = oldMaskTypesNone;
});

0 comments on commit 739997f

Please sign in to comment.