Hello,
We have a problem with a NumericTextBox within a Grid.
We would like to automatically select the text when the control NumericTextBox take focus (or only when the input value is 0).
This is defined in a NumericTextBox EditorTemplate as follows in the attached word file. I had to attach a file because of losing text formats while copy/pasting in your rich text editor in this forum (with IE10+Office2013+Win8):
Do you have an idea to make it because we are requested to do it for an intensively used and critical application ?
Thx
Mathieu P
.Net Developper
DEVOTEAM Application Practice (Luxembourg)
8 Answers, 1 is accepted
In order to achieve the expected result you could attach a handler to the Grid edit event and use the select() method with setTimeout. For example:
@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()
//....
.Events(ev=>ev.Edit(
"selectText"
))
)
<script>
function
selectText(e) {
$(e.container).find(
".k-input.k-textbox"
).select();
$(
'.k-input'
).on(
'focus'
,
function
() {
var
input = $(
this
);
setTimeout(
function
() {
input.select();
});
});
}
</script>
Regards,
Iliana Nikolova
Telerik
Thank you for your reply.
But I don’t have the event "edit" in my grid. Any idea?
See update and screenshot on the attached file
Mathieu
Edit is an event of the Grid not of the dataSource. I.e. thy the following:
@(Html.Kendo().Grid(Model.Packages)
//....
.DataSource(dataSource => dataSource.Ajax()
//....
)
.Events(ev=>ev.Edit(
"selectText"
))
)
Regards,
Iliana Nikolova
Telerik
This worked great for me, but why have the setTimeout?
Regards,
Daniel
I would suggest vote for this functionality in the corresponding UserVoice item. Its implementation is directly related to the votes it has.
Regards,
Georgi Krustev
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
I would like to share with you that as of Kendo UI version 2020.2.617, our team has added the "SelectOnFocus" method covering the pointed requirements in this thread. For your future web development, feel free to utilize this implementation shown here:
@(Html.Kendo().NumericTextBox()
.SelectOnFocus(true)
.Name("numerictextbox") // The name of the NumericTextBox is mandatory. It specifies the "id" attribute of the widget.
.Min(-100) // Set the min value of the NumericTextBox.
.Max(100) // Set the min value of the NumericTextBox.
.Value(10) // Set the value of the NumericTextBox.
)
Kind Regards,
Anton Mironov
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/.