Get value of RadHtmlField using javascript

6 posts, 0 answers
  1. Hung
    Hung avatar
    10 posts
    Member since:
    Apr 2011

    Posted 11 Apr 2011 Link to this post

    Hi,
    My client want to validate (required field)  for RadHtmlField. But I saw the generated html by RadHtmlField so complex (there are a lot tag span, div, table inside each other). Is there a way to get value of RadHtmlField using javascript?
    I appreciate your help.
    Thanks.
  2. Stanimir
    Admin
    Stanimir avatar
    1653 posts

    Posted 11 Apr 2011 Link to this post

    Hi Hung,

    You can try the following javascript code:
    if ($telerik)
    {
        var controls = $telerik.radControls;
        for (var i = 0, l = controls.length; i < l; i++)
        {
        if (controls[i] instanceof Telerik.Web.UI.RadEditor)
        {
            var editor = controls[i];
            alert(editor.get_html(true));
        }
        }
    }

    The mentioned code is if you are Using RadEditor for MOSS5.x. If you are using the Lite version of the controls (4.x), you can access all editors via the follwoing code:
    var oArray = RadEditorGlobalArray;  
        for (var i = 0; i < oArray.length; i++)  
        {  
            //Do what you need with each editor here  
            var editor = oArray[i];  
            alert (editor.GetHtml(true));  
        }


    Regards,
    Stanimir
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

  3. Hung
    Hung avatar
    10 posts
    Member since:
    Apr 2011

    Posted 13 Apr 2011 Link to this post

    Hi Stanimir,
    Currently, I am using RadEditor for Moss 5.6.1.
    It looks good for me. I tried with your code, it work well.
    But I concern about how I can find a radEditor field which I need to validate?
    Example: 

     if ($telerik)
    {
        var controls = $telerik.radControls;
        for (var i = 0, l = controls.length; i < l; i++)
        {
        if (controls[i] instanceof Telerik.Web.UI.RadEditor)
        {
            var editor = controls[i];
    if(editor.getElement.getAttribute("title") == "Email Body")
    {
    alert(editor.get_html(true));
    }
        }
        }
    }

    Because I see in your code, you loop all radEditor fields in page. I just want to get a radEditor field I need. 
    Example: I defined html field in content type such as:
    <Field ID="{868AF0D1-935E-438e-B19E-65CE6A6CD65E}"
             Type="HTML"
             Name="Confirmation"
             DisplayName="Confirmation"
             Group="Forms Properties Columns"
             Hidden="FALSE"
             Required="FALSE"
             Sealed="FALSE"
             Description="The body of email." />

    I validate in editform mode of Pages List.
    In my situation, I can not pass the ID of RadEditor field from server side to client side, I have only one way get radeditor field in client side.
    But I do not know how to get RadEditor field in your loop (in your code).
    Thanks.
  4. Stanimir
    Admin
    Stanimir avatar
    1653 posts

    Posted 15 Apr 2011 Link to this post

    Hello Hung,

     Check the following approach:
    1. Try with editor.get_id() method. This will give you the id of the editor. Check if there is some dependence between the field ID {868AF0D1-935E-438e-B19E-65CE6A6CD65E} and the value returned by editor.get_id().
    2. Inspect the HTML rendered by RadEditor. You can use IE developers toolbar or FireBug for FireFox. Check the IDs of the content area and in all the elements at all and look if there is a dependence.

    You might need to do something like
    var id = editor.get_id();
    if (id.indexOf("868AF0D1_935E_438e_B19E_65CE6A6CD65E") != -1)
    {
        //do validation
    }

    I will also suggest you to use the javascript debuggers in IE Developers toolbar or FireBug and review the editor variable in the code.



    Best wishes,
    Stanimir
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  5. Hung
    Hung avatar
    10 posts
    Member since:
    Apr 2011

    Posted 15 Apr 2011 Link to this post

    Hi Stanimir,
    I tried your code, all radEditor in a page always return the same id such as "868AF0D1_935E_438e_B19E_65CE6A6CD65E".
    I do not know how to detect which ID of radEditor I need.
    Is there other way for this solution?
    Thanks.
  6. Stanimir
    Admin
    Stanimir avatar
    1653 posts

    Posted 19 Apr 2011 Link to this post

    Hello Hung,

    Here is what I suggest you to do. Try achieving the desired functionality with the OOB MOSS editor. Just disable the "Use RadEditor to edit List Items" feature. Once you do this provide me with your source code and I will tell you how to enable it for RadEditor for MOSS.


    Regards,
    Stanimir
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Back to Top