how to add a format object dynamically

Hello,

I want to add a format object to a text widget after the widget is rendered:

{ view:“text”, id:“test”, value:‘12345678’, name:“f”, label:“Test”},

how do I add a format object like below to the text widget after the text widget has been rendered? I tried it with the define() function but didnt quite know how to do that. The reason for it is that the same text widget may be formatted different for one user or the other.

format:{
parse: function(a){ return a.replace(/[^0-9]*/g,""); },
edit: function(a){
function chunk(a, n){
return a.length > n ? (a.substr(0,n) + “-” + chunk(a.substr(n), n)): a;
}
return (a.length ? “+”: “”) + chunk(a, 3);
},
}

I have also tried to define the pattern property after the text widget is rendered and I cant get that to work either.
$$(“test”).define(“pattern”,"##-###-###-###");
$$(“test”).refresh();

Is there a different way the formatting of a text widget can be set after its rendered?

thanks,
Pieter

Hello @Pieter ,

how do I add a format object like below to the text widget after the text widget has been rendered? I tried it with the define() function but didnt quite know how to do that. The reason for it is that the same text widget may be formatted different for one user or the other.

As a solution, you can try this:
https://snippet.webix.com/j25xvqqh

I have also tried to define the pattern property after the text widget is rendered and I cant get that to work either.

You can define the pattern using “define”+“refresh” method, but please note that the pattern can be initialized only at the time of creating text, so this solution will only work if the mask was originally set.
Please check the next example: Code Snippet

Thank you. I will give these solutions a try.