Disable "Remove Link" until the cursor is on a link?

4 posts, 0 answers
  1. Trevor
    Trevor avatar
    53 posts
    Member since:
    Jan 2012

    Posted 25 May 2012 Link to this post

    Customer is requesting the "Remove Link" toolbar button be disabled/unavailable until the cursor is moved onto a link in the editor content. Is this possible to do?

    Thanks.
  2. Rumen
    Admin
    Rumen avatar
    14421 posts

    Posted 25 May 2012 Link to this post

    Hi,

    You can use the editor.getSelectedElement() method to check whether the selected element is A tag and if it is to disable the Unlink button using the setState() method. This could be implemented in the OnClientSelectionChange event of RadEditor.

    All the best,
    Rumen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. Trevor
    Trevor avatar
    53 posts
    Member since:
    Jan 2012

    Posted 25 May 2012 Link to this post

    Hi Rumen,

    Thanks for the response. I implemented the following code:

    function OnClientSelectionChange(editor, args){
        var elem = editor.getSelectedElement();
        var tool=editor.getToolByName("Unlink");
        if((tool)&&(elem.tagName == "A")){
            tool.setState(0);
        }else{
            tool.setState(-1);
        }
    }

    This does correctly set the state of the toolbar button; however, immediately after completing execution of this function, the toolbar button becomes unconditionally enabled again. It seems the editor is executing some other code that sets the state of the toolbar button after calling this function.
  4. Rumen
    Admin
    Rumen avatar
    14421 posts

    Posted 28 May 2012 Link to this post

    Hi,

    Try with small timeout, e.g.

    <telerik:RadEditor ID="RadEditor1" runat="server" OnClientSelectionChange="OnClientSelectionChange">
            <Content><a href="http://www.telerik.com">Telerik</a></Content>
        </telerik:RadEditor>  
        <script type="text/javascript">
            function OnClientSelectionChange(editor, args) {
                var elem = editor.getSelectedElement();
                var tool = editor.getToolByName("Unlink");
                if ((tool) && (elem.tagName == "A")) {
                    setTimeout(function () {
                        tool.setState(-1);
                    }, 100);
                }
            }
        </script>

    Greetings,
    Rumen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top