Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
228
dropdown caret position
posted

Hi,

 

I have a web drop down ...

 

 

                            <ig:WebDropDown ID="wddUsers" runat="server" DropDownAnimationType="Bounce" DropDownContainerMaxHeight="85px"

                                EnableAutoFiltering="Client" EnableDropDownAsChild="False" EnableRenderingAnchors="False"

                                StyleSetName="Default" Width="175px" DropDownContainerHeight="85px">

                                <ClientEvents ValueChanged="wddUsers_ValueChanged" Focus="wdd_Focus" ValueChanging="wdd_ValueChanging" DropDownClosing="wddUsers_DropDownClosing" />

                            </ig:WebDropDown>

... that I would like to have the caret move back to the beginning of the user's selection after the control looses focus.

 

Parents
  • 24671
    Verified Answer
    posted

    Hi ,

    Yes this is possible. IT's kind of tricky, but i have created a solution for you. Please follow the following steps:

    1) Set this client-side event for ValueChanged:

    <ClientEvents ValueChanged="setCaretToStart" />

    2) then define the following javascript in your page:

    <script type="text/javascript">

     

    function resetCaret() {

    pos = 0;

    ctrl = $find("WebDropDown1")._elements["Input"]; // change this to the server-side ID of your DropDown control

    if (ctrl.setSelectionRange) { //FF, etc.

    ctrl.focus();

    ctrl.setSelectionRange(pos, pos);

    }

    else if (ctrl.createTextRange) { // IE

    var range = ctrl.createTextRange();

    range.collapse(true);

    range.moveEnd('character', pos);

    range.moveStart('character', pos);

    range.select();

    }

    }

     

    function setCaretToStart(sender, args) {

    setTimeout("resetCaret()", 50);

    }

    </script>

    And that should do it. The setTimeout workaround is necessary only for IE, because for some reason it doesn't directly update the caret, there needs to be some timeout in between.

    Please let me know whether this works for you.

    Thank you,

    Angel 

Reply Children
No Data