Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

survey.onTextMarkdown - The options.element contains a top-level Radi… #9606

Merged
merged 4 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/survey-core/src/actions/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ export class Action extends BaseAction implements IAction, ILocalizableOwner {

//ILocalizableOwner
getLocale(): string { return this.owner ? this.owner.getLocale() : ""; }
getMarkdownHtml(text: string, name: string): string { return this.owner ? this.owner.getMarkdownHtml(text, name) : undefined; }
getMarkdownHtml(text: string, name: string, item?: any): string { return this.owner ? this.owner.getMarkdownHtml(text, name, item) : undefined; }
getProcessedText(text: string): string { return this.owner ? this.owner.getProcessedText(text) : text; }
getRenderer(name: string): string { return this.owner ? this.owner.getRenderer(name) : null; }
getRendererContext(locStr: LocalizableString): any { return this.owner ? this.owner.getRendererContext(locStr) : locStr; }
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-core/src/actions/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export let defaultActionBarCss: ActionBarCssClasses = {
};

export class ActionContainer<T extends BaseAction = Action> extends Base implements ILocalizableOwner {
public getMarkdownHtml(text: string, name: string): string {
return !!this.locOwner ? this.locOwner.getMarkdownHtml(text, name) : undefined;
public getMarkdownHtml(text: string, name: string, item?: any): string {
return !!this.locOwner ? this.locOwner.getMarkdownHtml(text, name, item) : undefined;
}
public getRenderer(name: string): string {
return !!this.locOwner ? this.locOwner.getRenderer(name) : null;
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/src/base-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export interface ISurvey extends ITextProcessor, ISurveyErrorOwner {
hasVisibleQuestionByValueName(valueName: string): boolean;
questionsByValueName(valueName: string): Array<IQuestion>;
processHtml(html: string, reason: string): string;
getSurveyMarkdownHtml(element: Base, text: string, name: string): string;
getSurveyMarkdownHtml(element: Base, text: string, name: string, item?: any): string;
getRendererForString(element: Base, name: string): string;
getRendererContextForString(element: Base, locStr: LocalizableString): any;
getExpressionDisplayValue(
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-core/src/expressionItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export class ExpressionItem extends Base implements ILocalizableOwner {
public getLocale(): string {
return !!this.locOwner ? this.locOwner.getLocale() : "";
}
public getMarkdownHtml(text: string, name: string): string {
return !!this.locOwner ? this.locOwner.getMarkdownHtml(text, name) : undefined;
public getMarkdownHtml(text: string, name: string, item?: any): string {
return !!this.locOwner ? this.locOwner.getMarkdownHtml(text, name, item) : undefined;
}
public getRenderer(name: string): string {
return !!this.locOwner ? this.locOwner.getRenderer(name) : null;
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-core/src/itemvalue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { Question } from "./question";
export class ItemValue extends BaseAction implements ILocalizableOwner, IShortcutText {
[index: string]: any;

public getMarkdownHtml(text: string, name: string): string {
return !!this.locOwner ? this.locOwner.getMarkdownHtml(text, name) : undefined;
public getMarkdownHtml(text: string, name: string, item?: any): string {
return !!this.locOwner ? this.locOwner.getMarkdownHtml(text, name, item || this) : undefined;
}
public getRenderer(name: string): string {
return !!this.locOwner ? this.locOwner.getRenderer(name) : null;
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/src/localizablestring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { SurveyElementCore } from "./survey-element";

export interface ILocalizableOwner {
getLocale(): string;
getMarkdownHtml(text: string, name: string): string;
getMarkdownHtml(text: string, name: string, item?: any): string;
getProcessedText(text: string): string;
getRenderer(name: string): string;
getRendererContext(locStr: LocalizableString): any;
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-core/src/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ export class PageModel extends PanelModel implements IPage {
this.locNavigationTitle.strChanged();
this.locNavigationDescription.strChanged();
}
getMarkdownHtml(text: string, name: string): string {
const result = super.getMarkdownHtml(text, name);
getMarkdownHtml(text: string, name: string, item?: any): string {
const result = super.getMarkdownHtml(text, name, item);
if (name === "navigationTitle" && this.canShowPageNumber() && result) {
return this.num + ". " + result;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-core/src/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,11 @@ export class PanelModelBase extends SurveyElement<Question>
this.elements[i].locStrsChanged();
}
}
getMarkdownHtml(text: string, name: string): string {
getMarkdownHtml(text: string, name: string, item?: any): string {
if(name === "navigationTitle" && this.locNavigationTitle.isEmpty) {
return this.locTitle.renderedHtml || this.name;
}
return super.getMarkdownHtml(text, name);
return super.getMarkdownHtml(text, name, item);
}
public get locNavigationTitle(): LocalizableString {
return this.getLocalizableString("navigationTitle");
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-core/src/question_imagepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export class ImageItemValue extends ItemValue implements ILocalizableOwner {
getLocale(): string {
return !!this.locOwner ? this.locOwner.getLocale() : "";
}
getMarkdownHtml(text: string, name: string): string {
return !!this.locOwner ? this.locOwner.getMarkdownHtml(text, name) : undefined;
getMarkdownHtml(text: string, name: string, item?: any): string {
return !!this.locOwner ? this.locOwner.getMarkdownHtml(text, name, item) : undefined;
}
getRenderer(name: string): string {
return !!this.locOwner ? this.locOwner.getRenderer(name) : null;
Expand Down
6 changes: 3 additions & 3 deletions packages/survey-core/src/question_matrixdropdownbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export interface IMatrixDropdownData {
): Question;
choices: Array<ItemValue>;
getLocale(): string;
getMarkdownHtml(text: string, name: string): string;
getMarkdownHtml(text: string, name: string, item?: any): string;
getRenderer(name: string): string;
getRendererContext(locStr: LocalizableString): any;
getProcessedText(text: string): string;
Expand Down Expand Up @@ -687,8 +687,8 @@ export class MatrixDropdownRowModelBase implements ISurveyData, ISurveyImpl, ILo
public getLocale(): string {
return this.data ? this.data.getLocale() : "";
}
public getMarkdownHtml(text: string, name: string): string {
return this.data ? this.data.getMarkdownHtml(text, name) : undefined;
public getMarkdownHtml(text: string, name: string, item?: any): string {
return this.data ? this.data.getMarkdownHtml(text, name, item) : undefined;
}
public getRenderer(name: string): string {
return this.data ? this.data.getRenderer(name) : null;
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-core/src/question_matrixdropdowncolumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,8 @@ export class MatrixDropdownColumn extends Base
public getLocale(): string {
return this.colOwner ? this.colOwner.getLocale() : "";
}
public getMarkdownHtml(text: string, name: string): string {
return this.colOwner ? this.colOwner.getMarkdownHtml(text, name) : undefined;
public getMarkdownHtml(text: string, name: string, item?: any): string {
return this.colOwner ? this.colOwner.getMarkdownHtml(text, name, item) : undefined;
}
public getRenderer(name: string): string {
return !!this.colOwner ? this.colOwner.getRenderer(name) : null;
Expand Down
8 changes: 4 additions & 4 deletions packages/survey-core/src/survey-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export abstract class SurveyElementCore extends Base implements ILocalizableOwne
protected getIsTitleRenderedAsString(): boolean { return !this.isTitleOwner; }
//ILocalizableOwner
public abstract getLocale(): string;
public abstract getMarkdownHtml(text: string, name: string): string;
public abstract getMarkdownHtml(text: string, name: string, item?: any): string;
public abstract getRenderer(name: string): string;
public abstract getRendererContext(locStr: LocalizableString): any;
public abstract getProcessedText(text: string): string;
Expand Down Expand Up @@ -809,11 +809,11 @@ export class SurveyElement<E = any> extends SurveyElementCore implements ISurvey
? this.locOwner.getLocale()
: "";
}
public getMarkdownHtml(text: string, name: string): string {
public getMarkdownHtml(text: string, name: string, item?: any): string {
return this.survey
? this.survey.getSurveyMarkdownHtml(this, text, name)
? this.survey.getSurveyMarkdownHtml(this, text, name, item)
: this.locOwner
? this.locOwner.getMarkdownHtml(text, name)
? this.locOwner.getMarkdownHtml(text, name, item)
: undefined;
}
public getRenderer(name: string): string {
Expand Down
12 changes: 8 additions & 4 deletions packages/survey-core/src/survey-events-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,15 +466,19 @@ export interface ProgressTextEvent extends GetProgressTextEvent { }

export interface TextProcessingEvent {
/**
* The name of the property that contains the text to process.
* A survey element (question, panel, page, or survey) for which the event is raised.
*/
name: string;
element: Question | PanelModel | PageModel | SurveyModel;
/**
* A survey element (question, panel, page, or survey) in which the text will be rendered.
* The name of the property that contains the text to process.
*/
element: Question | PanelModel | PageModel | SurveyModel;
name: string;
}
export interface TextMarkdownEvent extends TextProcessingEvent {
/**
* A choice item for which the event is raised. This parameter has a value only when `options.element` is a choice-based question, such as [Dropdown](https://surveyjs.io/form-library/documentation/api-reference/dropdown-menu-model) or [Checkboxes](https://surveyjs.io/form-library/documentation/api-reference/checkbox-question-model).
*/
item?: ItemValue;
/**
* A string with Markdown content. Convert this content to HTML and assign the result to the `options.html` parameter.
*/
Expand Down
9 changes: 5 additions & 4 deletions packages/survey-core/src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2148,8 +2148,8 @@ export class SurveyModel extends SurveyElementCore
this.navigationBar.locStrsChanged();
}
}
public getMarkdownHtml(text: string, name: string): string {
return this.getSurveyMarkdownHtml(this, text, name);
public getMarkdownHtml(text: string, name: string, item?: any): string {
return this.getSurveyMarkdownHtml(this, text, name, item);
}
public getRenderer(name: string): string {
return this.getRendererForString(this, name);
Expand Down Expand Up @@ -7378,12 +7378,13 @@ export class SurveyModel extends SurveyElementCore
}
return this.textPreProcessorValue;
}
getSurveyMarkdownHtml(element: Question | PanelModel | PageModel | SurveyModel, text: string, name: string): string {
getSurveyMarkdownHtml(element: Question | PanelModel | PageModel | SurveyModel, text: string, name: string, item: any): string {
const options: TextMarkdownEvent = {
element: element,
text: text,
name: name,
html: null,
item: item,
html: null
};
this.onTextMarkdown.fire(this, options);
return options.html;
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-core/src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ export class SurveyValidator extends Base {
getLocale(): string {
return !!this.errorOwner ? this.errorOwner.getLocale() : "";
}
getMarkdownHtml(text: string, name: string): string {
getMarkdownHtml(text: string, name: string, item?: any): string {
return !!this.errorOwner
? this.errorOwner.getMarkdownHtml(text, name)
? this.errorOwner.getMarkdownHtml(text, name, item)
: undefined;
}
getRenderer(name: string): string {
Expand Down
22 changes: 10 additions & 12 deletions packages/survey-core/tests/questionDropdownTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,30 +364,28 @@ QUnit.test("ListModel localization", assert => {
assert.equal(listModel.filterStringPlaceholder, "Tippen Sie, um zu suchen...", "filtered text in de");
survey.locale = "";
});
QUnit.test("readOnlyText default", assert => {
QUnit.test("survey.onTextMarkdown, options.item #9601", assert => {
const json = {
questions: [
{
"type": "dropdown",
"name": "q1",
"placeholder": "click",
"hasOther": true,
"showNoneItem": true,
"choices": [{ value: 1, text: "item 1" }, { value: 2, text: "item 2" }, { value: 3, text: "item 3" }]
"choices": [{ value: 1, text: "Item 1" }, { value: 2, text: "Item 2" }, { value: 3, text: "Item 3" }]
}]
};
const survey = new SurveyModel(json);
const itemsValues = new Array<string>();
survey.onTextMarkdown.add((sender, options) => {
if(options.item) {
itemsValues.push(options.item.value);
}
options.html = options.text + "_" + options.text;
});
const question = <QuestionDropdownModel>survey.getAllQuestions()[0];
assert.equal(question.readOnlyText, "click", "use place-holder");
question.value = "other";
assert.equal(question.readOnlyText, "", "use other");
question.value = "none";
assert.equal(question.readOnlyText, "", "use none text");
question.value = 2;
assert.equal(question.readOnlyText, "", "use choice text");
assert.equal(question.choices[0].locText.textOrHtml, "Item 1_Item 1", "choices[0]");
assert.equal(question.choices[1].locText.textOrHtml, "Item 2_Item 2", "choices[1]");
assert.equal(question.choices[2].locText.textOrHtml, "Item 3_Item 3", "choices[2]");
assert.deepEqual(itemsValues, [1, 2, 3]);
});
QUnit.test("readOnlyText visibleChoices changed", assert => {
const json = {
Expand Down