This is a migrated thread and some comments may be shown as answers.
OnValueChanged Cancel
4 Answers 64 Views
This is a migrated thread and some comments may be shown as answers.
Maas Prog
Top achievements
Rank 1
Maas Prog asked on 02 Dec 2009, 08:26 PM
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



4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 03 Dec 2009, 06:08 AM
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.
0
Maas Prog
Top achievements
Rank 1
answered on 03 Dec 2009, 09:13 PM
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
0
Accepted
Shinu
Top achievements
Rank 1
answered on 04 Dec 2009, 07:42 AM
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.
0
Maas Prog
Top achievements
Rank 1
answered on 04 Dec 2009, 11:01 PM
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
Tags
Input
Asked by
Maas Prog
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Maas Prog
Top achievements
Rank 1
Share this question
or