getToolByName() semms to return only nulls

3 posts, 1 answers
  1. Nils
    Nils avatar
    46 posts
    Member since:
    Jul 2009

    Posted 05 Dec 2012 Link to this post

    Hi,
    in some pages I need to hide Tool-Buttons from a RadEditor.
    So I attached an OnClientLoad function and in there wanted to remove the Tools.
    But editor.getToolByName seems to always return null.
    I am using a ToolBarMode of "Floating" could it be, that getToolByName only works when the Toolbar is visible?

    Best,
    Nils
  2. Answer
    Rumen
    Admin
    Rumen avatar
    12846 posts

    Posted 06 Dec 2012 Link to this post

    Hi Nils,

    Here is an example how to get reference to a tool in RadWindow based toolbar:

    <telerik:RadEditor runat="server" ID="RadEditor1" ToolbarMode="ShowOnFocus" OnClientLoad="OnClientLoad"></telerik:RadEditor>
    <script type="text/javascript">
        function OnClientLoad(editor) {
            var wnd = editor.get_toolAdapter().get_window();
            wnd.add_show(function () {
                setTimeout(function () {
                    var tool = editor.getToolByName("RealFontSize");
                    tool.set_value("13px");
                }, 100);
            });
        }
    </script>

    If you work in SharePoint environment, see this article: Using RadEditor's Client-Side events in SharePoint 2010.


    Regards,
    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. Nils
    Nils avatar
    46 posts
    Member since:
    Jul 2009

    Posted 11 Dec 2012 Link to this post

    Thanks Rumen,
    I have now the following up-and-running. (TypeScript-Code)
        export class RadEditor  {
            public static ClientLoaded(editor, args) {           
                console.info("RadEditor loaded: " + editor.get_id());
                var wnd = (<Telerik.Web.UI.RadEditor>editor).get_toolAdapter().get_window();
                wnd.add_show(() => {
                    if (ShouldHideButtons()) {
                        setTimeout(() => {
                            $.each(
                            [
                                "EditReusableContent",
                                "MedInsertCT",
                                "SPTemplateManager"
                            ], (i, name) => {
                                var tool = <Telerik.Web.UI.EditorButton>editor.getToolByName(name);
                                if (!tool)
                                    return;
                                //tool.set_enabled(false);
                                //tool.setState(-1);
                                tool.set_visible(false);
                                console.info(name + " hidden in " + editor.get_id());
                            })
                        }, 100);
                    }
                });
             }
    //... rest...
    }

    or in JavaScript:
            var RadEditor = (function () {
                function RadEditor() { }
                RadEditor.ClientLoaded = function ClientLoaded(editor, args) {
                    console.info("RadEditor loaded: " + editor.get_id());
                    var wnd = (editor).get_toolAdapter().get_window();
                    wnd.add_show(function () {
                        if(ShouldHideButtons()) {
                            setTimeout(function () {
                                $.each([
                                    "EditReusableContent",
                                    "MedInsertCT",
                                    "SPTemplateManager"
                                ], function (i, name) {
                                    var tool = editor.getToolByName(name);
                                    if(!tool) {
                                        return;
                                    }
                                    //tool.set_enabled(false);
                                    //tool.setState(-1);
                                    tool.set_visible(false);
                                    console.info(name + " hidden in " + editor.get_id());
                                });
                            }, 100);
                        }
                    });
                }
               // ... rest...
    }

    Where RadEditor.ClientLoaded is set as the OnClientLoad-Function.
    Thanks again.

    Best, Nils
Back to Top