This is a migrated thread and some comments may be shown as answers.

How to select/highlight values inside NumericTexBox

2 Answers 113 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
Shawn
Top achievements
Rank 1
Shawn asked on 07 Mar 2019, 07:49 PM

Hello,

In my Grid's Edit PopUp window I have a Kendo NumericTextBoxFor input control to allow the user to add/edit values in the Grid and the underlying model.  When I want to insert a record the NumericTextBox displays a zero "0" which is fine.  However, when the user tabs to this text box or when it gets focus I want the "0" to be highlighted/selected so that the user can change it to a different value without having to click either the delete button or the backspace button to get rid of the "0".  Currently, when the user tabs to this text box the value is momentarily highlighted for a split-second.  Is there a way to have the value get highlighted and stay highlighted until the user tabs out of this input box? 

This is my HTML:

@Html.Kendo().NumericTextBoxFor(model => model.ReplacementCost).Format("C0").Decimals(0).Placeholder("...").HtmlAttributes(new { style = "width: 200px; background-color: white;" }).Spinners(false).Events(e => e
    .Change("replacementCost_change"))

 

This is the script to make it so that the validation message doesn't show if the user clears the value in the text box:

function replacementCost_change() {
    var txtLatitude = $("#ReplacementCost").data("kendoNumericTextBox");
    if ($("#ReplacementCost").val() === '') {
        txtLatitude.value(0);
        txtLatitude.trigger('change');
    }
}

 

Thanks.

Shawn A.

2 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 11 Mar 2019, 01:26 PM
Hello Shawn,

Once the NumericTextBox is initialized you could attach handler for the "focus" event of the input element and manually call the "select" method over it:
$("#theID").focus(function(){
  var input = $(this)
  setTimeout(function(){
input.select();                   
  })
})


Best Regards,
Konstantin Dikov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Shawn
Top achievements
Rank 1
answered on 14 Mar 2019, 07:04 PM

Hello Konstantin,

Thank you for your help!  This worked perfectly for me.

<div>
                @(Html.Kendo().NumericTextBoxFor(model => model.ReplacementCost)
                            .Format("C0").Decimals(0).Placeholder("...")
                            .HtmlAttributes(new { style = "width: 200px; background-color: white;" })
                            .Spinners(false)
                            .Events(e => e
                                .Change("replacementCost_change")))
 
                <script>
                    $("#ReplacementCost").focus(function () {
                        var input = $(this);
                        setTimeout(function () {
                            input.select();
                        });
                    });
                </script>
</div>

 

Regards,

Shawn A.

Tags
NumericTextBox
Asked by
Shawn
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Shawn
Top achievements
Rank 1
Share this question
or