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

Disabling a numeric Textbox

14 Answers 534 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Anil
Top achievements
Rank 1
Anil asked on 27 Apr 2010, 01:51 PM
Good morning. I have a numeric textbox on my view as follows:

 

<%= Html.Telerik().IntegerTextBox().Name("IntegerTextBox")

.MinValue(-5)

.MaxValue(10) %>

I want to disable it, so that nothing could be typed in the textbox, and it should be grayed out.
I am doing it using jQuery,

 

$(

function() {

 

$(

"#IntegerTextBox").attr("disabled", true)

 

$(

"#IntegerTextBox-input-text").attr("disabled", true)

 

$(

"#IntegerTextBox").find('a').unbind('mousedown')

 

});

It grays out the textbox, but does not disable it. Please suggest the way to disable it, so that nothing could be typed in it.
Thanks
Anil

14 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 27 Apr 2010, 04:05 PM
Hello Anil,

Please examine the test project which I have created in order to achieve your goal.

Sincerely yours,
Georgi Krustev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Anil
Top achievements
Rank 1
answered on 27 Apr 2010, 04:39 PM
Thanks, that works. But when I try to put the same logic on page load like this,

 

<%

= Html.Telerik().NumericTextBox()

 

.Name(

"NumericTextBox")

 

.Value(1)

%>



$(

function() {

 

 

 var $NumericTextBox = $('#NumericTextBox');

 

 

 $NumericTextBox.find('> #NumericTextBox-input-text').attr('disabled', true);

 

 

 $NumericTextBox.find('.t-arrow-up, .t-arrow-down').unbind('mousedown');

 

});

it does not work. I do not want to disable it on click of a button. It should be disabled on page load. Please suggest what is wrong.

Thanks
Anil

0
Atanas Korchev
Telerik team
answered on 28 Apr 2010, 07:23 AM
Hello Anil,

You should use the OnLoad event of the textbox or OnDocumentReady of the ScriptRegistrar. Here is an example for the first option:

<%= Html.Telerik().NumericTextBox()
                  .Name("NumericTextBox")
                  .Value(1)
                  .ClientEvents(events => events.OnLoad("onLoad"))
%>

<script type="text/javascript">
function onLoad() {
    var $NumericTextBox = $('#NumericTextBox');
    $NumericTextBox.find('> #NumericTextBox-input-text').attr('disabled', true);
    $NumericTextBox.find('.t-arrow-up, .t-arrow-down').unbind('mousedown');
}
</script>



All the best,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Anil
Top achievements
Rank 1
answered on 04 May 2010, 04:43 PM
Thanks. It works. I am also using the onchange event. But, the problem is that when onchange of value from, lets say, 30 -> 32,

<%

= Html.Telerik().CurrencyTextBox()

 

.Name(

"CurrTxtBoxNACost")

 

.Spinners(

true)

 

.MinValue(0)

.MaxValue(

decimal.MaxValue).Value(Model.NewAdditionCost)

 

.ClientEvents(events => events.OnLoad(

"onLoadNACost"))

 

.ClientEvents(events => events.OnChange("onChange"))
%>
 
in the onChange function, I get 30 as the value and not the most recent value 32.

 

 

var amtNewAddition = $("#CurrTxtBoxNACost-input").val(); ( this value should be the most recent value 32, not the value that was changed (i.e. 30).

Please let me know if there is a way to get the most recent value onChange event or OnBlur event. OnBlur event is not there in the API though.

Regards
Anil

 

0
Georgi Krustev
Telerik team
answered on 05 May 2010, 08:08 AM
Hello Anil,

Unfortunately, I could not reproduce the depicted issue. I have used our online demo for the client-events.
to reproduce described problem, but to no avail. You can examine it and let us know what the differences are.

To get the most recent value, you can use .value() method. For more information check this help topic.

All the best,
Georgi Krustev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Grant Chapman
Top achievements
Rank 1
answered on 14 May 2010, 04:10 AM
How would a function look that reversed the effects of this disable and re-enabled the spinners on the side?

        function Disable() {
            var $NumericTextBox = $('#NumericTextBox');
            $NumericTextBox.find('> #NumericTextBox-input-text').attr('disabled', true);
            $NumericTextBox.find('.t-arrow-up, .t-arrow-down').unbind('mousedown');
        }

I can get the field enabled again, but I am unsure what events to rebind to the spinner arrows;

        function Enable() {
            var $NumericTextBox = $('#NumericTextBox');
            $NumericTextBox.find('> #NumericTextBox-input-text').removeAttr('disabled');
            // $NumericTextBox.find('.t-arrow-up, .t-arrow-down').bind( -- not sure what to do here? -- );
        }

Or is there a better way to do this?

Regards,
Grant Chapman



0
Georgi Krustev
Telerik team
answered on 14 May 2010, 07:30 AM
Hello Grant Chapman,

You can try with the following code snippet:
function Enable() {
            var $NumericTextBox = $('#NumericTextBox');
            $NumericTextBox.find('> #NumericTextBox-input-text').removeAttr('disabled');      
 
    var buttons = $NumericTextBox.find('.t-arrow-up, .t-arrow-down');
 
 
        $(buttons[0]).mousedown($.proxy(function (e) {
            $NumericTextBox.updateState();
            $NumericTextBox.stepper(e, 1);
        }, $NumericTextBox));
 
        $(buttons[1]).mousedown($.proxy(function (e) {
            $NumericTextBox.updateState();
            $NumericTextBox.stepper(e, -1);
        }, $NumericTextBox));
 
}


Greetings,
Georgi Krustev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Grant Chapman
Top achievements
Rank 1
answered on 14 May 2010, 07:46 AM
My sample View now looks like this (as per the example you posted in this thread) and the enable button does not re-enable the spinners.

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Home Page
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2><%= Html.Encode(ViewData["Message"]) %></h2>
    <%= Html.Telerik().NumericTextBox()
            .Name("NumericTextBox")
            .Value(1)
    %>
    <br />
    <input type="button" onclick="Disable()" value="Disable"/> <input type="button" onclick="Enable()" value="Enable"/>
    <script type="text/javascript">
        function Disable() {
            var $NumericTextBox = $('#NumericTextBox');
            $NumericTextBox.find('> #NumericTextBox-input-text').attr('disabled', true);
            $NumericTextBox.find('.t-arrow-up, .t-arrow-down').unbind('mousedown');
        }

        function Enable() {
            var $NumericTextBox = $('#NumericTextBox');
            $NumericTextBox.find('> #NumericTextBox-input-text').removeAttr('disabled');

            var buttons = $NumericTextBox.find('.t-arrow-up, .t-arrow-down');


            $(buttons[0]).mousedown($.proxy(function(e) {
                $NumericTextBox.updateState();
                $NumericTextBox.stepper(e, 1);
            }, $NumericTextBox));

            $(buttons[1]).mousedown($.proxy(function(e) {
                $NumericTextBox.updateState();
                $NumericTextBox.stepper(e, -1);
            }, $NumericTextBox));

        }
    </script>
</asp:Content>
0
Georgi Krustev
Telerik team
answered on 14 May 2010, 08:18 AM
Hello Grant,

I totally forgot that to achieve your goal you need to get the client object of the NumericTextBox component. Here is the correct code snippet:
function Enable() {
    var $NumericTextBox = $('#NumericTextBoxTest');
    $NumericTextBox.find('> #NumericTextBoxTest-input-text').removeAttr('disabled');
 
    var buttons = $NumericTextBox.find('.t-arrow-up, .t-arrow-down');
 
    var numericTextBox = $NumericTextBox.data('tTextBox');
    $(buttons[0]).mousedown($.proxy(function (e) {
        numericTextBox.updateState();
        numericTextBox.stepper(e, 1);
    }, numericTextBox));
 
    $(buttons[1]).mousedown($.proxy(function (e) {
        numericTextBox.updateState();
        numericTextBox.stepper(e, -1);
    }, numericTextBox));
 
}

Kind regards,
Georgi Krustev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Grant Chapman
Top achievements
Rank 1
answered on 21 May 2010, 07:22 AM
Georgi,

Unfortunately that enable function does not seem to work at all.

I have a new question and I am happy to start a new thread if you like but what I need to do is;
 - set focus to a numerictextbox via jQuery (or javascript) once I have selected the previous field (which happens to be a combobox).

I have tried the following;

$("#Input").focus();
$("#Input-input-text").focus();
$("#Input").click();
$("#Input-input-text").click();

But I cannot seem to get the NumericTextBox to gain focus.

Regards,
Grant Chapman
0
Georgi Krustev
Telerik team
answered on 21 May 2010, 05:07 PM
Hello Grant Chapman,

I have attached a simple test project, which implements the required functionality.

All the best,
Georgi Krustev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Grant Chapman
Top achievements
Rank 1
answered on 21 Jun 2010, 07:41 AM
Georgi,

Have just tried to enable or disable some Numeric Textboxes on $(document).ready() event within Jquery but have found that this doesnt work. Is there an event that I should be doing this in which is after the $(document).ready() event?

Without digging deeper I assume that these Numeric TextBox are initialised within a $(document).ready() event.

Regards,
Grant Chapman
0
andy
Top achievements
Rank 1
answered on 24 Jun 2010, 04:58 AM
I can't get the textbox to disable with the onload event.  It fires up okay, but the numeric textbox isn't being effected.  possibly the onload event is premature.

I've also tried running sepparately as a $(document).ready(function() { ... })  but same issue.

Any ideas?
0
Grant Chapman
Top achievements
Rank 1
answered on 25 Jun 2010, 09:16 AM
Georgi,

I am now running by form initialization code to disable some numerictextboxes in the $(window).load() event as this runs after all the $(document).ready() events.

Regards,
Grant Chapman
Tags
NumericTextBox
Asked by
Anil
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Anil
Top achievements
Rank 1
Atanas Korchev
Telerik team
Grant Chapman
Top achievements
Rank 1
andy
Top achievements
Rank 1
Share this question
or