-2

I am using C.K editor in my form, When I try to get the content in the CK editor I am getting Can't read property of 'getHTML' of undefined. the following is my code : This is my html:

    <aui:layout>
        <aui:column columnWidth="100">
            <liferay-ui:input-editor width="100%" name='<%= renderResponse.getNamespace()+"healthcontent" %>' height="550"  />
            <aui:input id="content" name="content" type="hidden" value='' />
            <div style="display: none;" id="<portlet:namespace/>healthcontentErrorDiv">
                <div class="portlet-msg-error">
                    Health Report content is required
                </div>
            </div>
        </aui:column>
    </aui:layout>

And below is my jquery code:

$jquery(".save-record").click(function(){
        try{
            alert('save record clicked');
            var flag = true;

            var title = $jquery("#<portlet:namespace/>title").val();

            alert("title is "+title);

            if(title == null || title.trim() == ""){

                $jquery("#<portlet:namespace/>titleErrorDiv").show();

                flag = false;
            }else{

                $jquery("#<portlet:namespace/>titleErrorDiv").hide();

            }

        var health_content = window.<portlet:namespace/>healthcontent.getHTML();

        alert("health_content is "+health_content);

        if(health_content != null && health_content.trim() != ""){
            $jquery("#<portlet:namespace/>content").val(health_content);
            $jquery("#<portlet:namespace/>healthcontentErrorDiv").hide();
        }else{
            $jquery("#<portlet:namespace/>healthcontentErrorDiv").show();
            flag = false;
        }

        // Submitting the form
        if(flag){
            $jquery("#<portlet:namespace/>HealthReportsAdministration").submit();   
        }
    }catch (e) {
        alert("Exception raised in HEALTH records11 "+e);
    }
});
ASR
  • 3,289
  • 3
  • 37
  • 65

2 Answers2

1

window.healthcontent.getHTML(); is the culprit line. There is no such object present with the window object. Probably what you should do is, on place of following line

<liferay-ui:input-editor width="100%" name='<%= renderResponse.getNamespace()+"healthcontent" %>' height="550"  />

Use

<liferay-ui:input-editor width="100%" name='<%= renderResponse.getNamespace()+"healthcontent" %>' id="<%= renderResponse.getNamespace()+"healthcontent" %>" height="550"  />

And then use

var health_content = $('#'+<portlet:namespace/>healthcontent);

Now do whatever you want on this variable.

Danish
  • 913
  • 8
  • 21
  • May be you can use the autogenerated ID by the edditor. Also you can select using the name of the Editor – Danish Mar 31 '15 at 07:45
0

I have modified to

<liferay-ui:input-editor width="100%" name="healthcontent" height="550"/> I have also modified inputCssClass so i changed it to cssClass.

ASR
  • 3,289
  • 3
  • 37
  • 65