Skip to content

Commit 47d31e3

Browse files
author
Heiner Pöpping
committed
🐛 Warn and remove unsupported formatter functions in input dialogs
Passing a function as a formatter is not supported in the app environment. Instead of stringifying the function, it is now removed and a warning is logged to the console to prevent unexpected behavior.
1 parent 090d942 commit 47d31e3

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/types/IChaynsReact.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ export interface DialogInput {
132132
placeholder?: string,
133133
inputType?: DialogInputType,
134134
defaultValue?: string,
135+
/**
136+
* Formats the input value shown in the dialog.
137+
* Not supported in app environments due to security reasons.
138+
* @param input
139+
*/
135140
formatter?: (input: string) => string,
136141
regex?: string
137142
}

src/wrapper/AppWrapper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,8 @@ export class AppWrapper implements IChaynsReact {
610610
},
611611
createDialog: <I, R>(config: Dialog<I>) => {
612612
if (config.type === DialogType.INPUT && typeof config.formatter === 'function') {
613-
config.formatter = config.formatter.toString();
613+
console.warn('[chayns-api] passing a function as formatter is not supported in the app environment, the formatter will be ignored');
614+
delete config.formatter;
614615
}
615616

616617
return new DialogHandler<R>(config, this.functions.openDialog, this.functions.closeDialog, this.functions.dispatchEventToDialogClient, this.functions.addDialogClientEventListener);

0 commit comments

Comments
 (0)