Subject says it all. I've got a grid that contains multiple NumericTextBoxes.... my users need to be able to copy and paste price values that contain formatting...commas, periods, dollar signs.
Can there be an option to automatically strip off / ignore formatting values in pasted data?
Thanks so much Dimo... I had actually stumbled upon dispatchEvent yesterday and sure enough.. it did the trick!!!
Hello Jeffrey,
In general, the Blazor framework ignores value changes "behind its back". The framework keeps the browser page state synchronized with the Razor component state in the .NET runtime. When something on the web page changes with JavaScript, it can be easily overridden in such scenarios.
You can "tell" the framework that the textbox value has changed - for example, dispatch the oninput event programmatically (we listen for it).
Here is a test page. The highlighted line makes all the difference.
<p>@NumValue.ToString()</p>
<TelerikNumericTextBox @bind-Value="@NumValue" Id="numtb" />
<script suppress-error="BL9992">
var i = setInterval(function() {
var input = document.getElementById("numtb");
input.value = (new Date()).getMilliseconds();
input.dispatchEvent(new Event('input', { bubbles: true, cancelable: true }));
}, 1234);
</script>
@code {
int NumValue { get; set; }
}
Regards,
Dimo
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
As an aside... In javascript, I implemented a dynamic event listener to the input elements that get generated in the grid to handle the paste event. The handler works and strips out the non-numeric values and then sets the value in the input element. (e.g. event.target.value = scrubbedData).
I see the value as expected on the web page, but when I leave the field, it reverts to the original value in the field which makes me think that somehow the NumericTextBox component isn't recognizing the value that is set via javascript.