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

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

3 Answers 40 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Trevor
Top achievements
Rank 1
Trevor asked on 25 May 2012, 06:19 PM
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.

3 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 25 May 2012, 09:35 PM
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.
0
Trevor
Top achievements
Rank 1
answered on 25 May 2012, 10:37 PM
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.
0
Rumen
Telerik team
answered on 28 May 2012, 03:04 PM
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.
Tags
Editor
Asked by
Trevor
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Trevor
Top achievements
Rank 1
Share this question
or