OnValueChanged Cancel

5 posts, 1 answers
  1. Maas Prog
    Maas Prog avatar
    48 posts
    Member since:
    Oct 2005

    Posted 02 Dec 2009 Link to this post

    Going crazy here:
    I am trying to validate a dynamically created RadNumericInput box. I have wired the OnValueCHanged event as follows:

    newControl.ClientEvents.OnValueChanged = "CheckAllocation"

    I have a javascript routine as follows (stripped down for example):

    function CheckAllocation(sender, eventArgs) {
     
    ...(do some checking and if number not good then...)

    sender.set_value(eventArgs.get_oldValue());
        eventArgs.set_cancel(true);
         sender.focus();
        return false;
        }

    I simply want to put the old value back in the box and return focus to the sender. The event fires fine and code seems to run, but the focus goes to wherever I clicked, and when I put the old value back in the box it fires OnValueChanged event again...

    Is there something I am missing? This seems like it should be pretty simple...

    Many Thanks
    Ford



  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 03 Dec 2009 Link to this post

    Hi Ford,

    Try attaching 'OnValueChanging' event instead of OnValueChanged to RadTextBox and you can cancel the event using the 'eventArgs.set_cancel(true);' method as shown below.

    javascript:
     
    <script type="text/javascript"
        function OnValueChanging(sender, eventArgs) { 
            if (sender.get_value() == "cancel") { // Check for condition 
                eventArgs.set_cancel(true); 
            } 
        } 
    </script> 

    -Shinu.
  3. Maas Prog
    Maas Prog avatar
    48 posts
    Member since:
    Oct 2005

    Posted 03 Dec 2009 Link to this post

    Hi Shinu -
    Thanks - of course.... another problem -- I want to set focus back to the sender when error. the following code does not work:
      eventArgs.set_cancel(true);
      sender.focus();
      return false;

    The original value stays, but focus still goes to whatever field I clicked. If I do this:

      eventArgs.set_cancel(true);
       return false;

    Focus does not happen anywhere and value changes.... what I want is focus on sender with all selected and old value.

    Almost there...

    Many Thanks
    Ford
  4. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 04 Dec 2009 Link to this post

    Hello Ford,

    Give a try with following code and check whether it helps.

    aspx:
     
       <telerik:RadTextBox ID="RadTextBox1" runat="server"
                <ClientEvents OnValueChanging="OnValueChanging" OnBlur="OnBlur" /> 
       </telerik:RadTextBox> 
            <br /> 
       <telerik:RadTextBox ID="RadTextBox2" runat="server"
       </telerik:RadTextBox> 

    javascript:
     
    <script type="text/javascript"
        var check = false
        var textbox; 
        function OnValueChanging(sender, eventArgs) { 
            if (sender.get_value() == "cancel") { // Check for condition 
                eventArgs.set_cancel(true); 
                check = true
            } 
        } 
        function OnBlur(sender, args) { 
            textbox = sender; 
            if (check) { 
                setTimeout("textbox.focus()", 300); 
                check = false
            } 
        } 
    </script> 

    -Shinu.
  5. Maas Prog
    Maas Prog avatar
    48 posts
    Member since:
    Oct 2005

    Posted 04 Dec 2009 Link to this post

    HI Shinu - Telerik support gave the following which is similar but a little simpler than you suggestion:

                    args.set_cancel(true);

                    window.setTimeout(function() { sender.focus(); }, 50);


    This seems to do the trick --

    Thanks   for your help!
    Ford
Back to Top