5 Answers, 1 is accepted
0
Hi Ian,
Georgi Krustev
the Telerik team
Could you please elaborate more on this? What is the require format ?
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Ian
Top achievements
Rank 1
answered on 05 Dec 2011, 06:23 PM
Hi,
Thanks for your interest. As an example, my viewmodel is returned from the server and has a phone field with a value 5553242345. I would like to bind this to a text input such that it is masked (555) 324-2345, and bind it to a label with the same format. In the past we have used a custom binding in knockout.js to perform this. Ideally, it would be great for the binding to automatically translate the value of the input from the masked/raw format.
Thanks again,
ian
Thanks for your interest. As an example, my viewmodel is returned from the server and has a phone field with a value 5553242345. I would like to bind this to a text input such that it is masked (555) 324-2345, and bind it to a label with the same format. In the past we have used a custom binding in knockout.js to perform this. Ideally, it would be great for the binding to automatically translate the value of the input from the masked/raw format.
Thanks again,
ian
0
Accepted
Hello Ian,
I am not expert in knockout.js, but I believe that you should create a value converter. Check this article for more information.
Regards,
Georgi Krustev
the Telerik team
In order to achieve your goal you will need to create a function, which will format the number into
"(###) ###-####" format. Once you have this function, you will be able to use it in the template to format the number:
function
format(number) {
//return formatted number;
}
var
inlineTemplate = kendo.template(
"The number is #= format(number) #."
);
var
inlineData = { number: 1234567890 };
$(
"#inline"
).html(inlineTemplate(inlineData));
I am not expert in knockout.js, but I believe that you should create a value converter. Check this article for more information.
Regards,
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Ian
Top achievements
Rank 1
answered on 07 Dec 2011, 02:57 PM
Thanks Georgi,
Yeah, this is actually what we ended up with. I was hoping for a bit of a cleaner syntax within our templates (where don't have to tote around a big list of functions from project to project simply for the equivalent of string.format function. I was hoping that kendo.toString(... function would support a custom formatter.
Thanks,
ian
Yeah, this is actually what we ended up with. I was hoping for a bit of a cleaner syntax within our templates (where don't have to tote around a big list of functions from project to project simply for the equivalent of string.format function. I was hoping that kendo.toString(... function would support a custom formatter.
Thanks,
ian
0
Gary
Top achievements
Rank 1
answered on 10 Apr 2012, 09:08 PM
Is it the case that any inline template that includes the '#' character needs to be externalized into a function. When I have an inline grid column template like:
'#= kendo.toString(number, "##,#") #'
I get an 'invalid template' error.
'#= kendo.toString(number, "##,#") #'
I get an 'invalid template' error.