I want to distinguish between the input value and the displayed value in TextBox

1 Answer 9 Views
Input
fingate
Top achievements
Rank 1
Iron
fingate asked on 09 Apr 2024, 04:46 AM

Hello,

When I use TextBox in Navtive components of Vue3, I want to distinguish between the input value and the displayed value.

For example,
I uesd TextBox like this.

<TextBox v-model="inputValue" />

If I enter "1234567", "1,234,567" will be displayed. but inputValue has "1234567".
or
If I enter "AbcD", "abcd" will be displayed. but inputValue has "AbcD".

Can I only change the displayed value while maintaining the value I entered?
ps... I don't want use the NumericTextBox. because of lowercase and uppercase.

1 Answer, 1 is accepted

Sort by
0
Filip
Telerik team
answered on 11 Apr 2024, 08:56 PM

Hello, fingate,

I understand that besides distinguishing between the input and displayed value, you wish to format the display value is that correct? 

If this is the case I can recommend putting the TextBox in controlled mode via the value prop, this will enable you to display the value as required and keep the original value that is inputted. I have created an example that showcases this approach here:

https://stackblitz.com/edit/fdnzsb-tk2yt9?file=src%2Fmain.vue

Here I am console.logging the rawValue that is obtained via `event.target.value`  and the display value is formatted in the formatValue function:

 formatValue(value) {
     return value.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
 }

I hope this helps.

Regards,
Filip
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources

Tags
Input
Asked by
fingate
Top achievements
Rank 1
Iron
Answers by
Filip
Telerik team
Share this question
or