Forums de discussion

How to get the value of Liferay input editor in a javascript variable

thumbnail
Jeet Chatterjee, modifié il y a 8 années.

How to get the value of Liferay input editor in a javascript variable

Junior Member Publications: 33 Date d'inscription: 22/11/14 Publications récentes
Hii ,

In my application i am using liferay-ui:input-editor .I want to get the value of input editor to a javascript variable, How to achieve that?? I have tried


<liferay-ui:input-editor />

<input name="<portlet:namespace />htmlCodeFromEditorPlacedHere" type="hidden" value="" />


function a(){
var x = document.<portlet:namespace />fm.<portlet:namespace />htmlCodeFromEditorPlacedHere.value = window.<portlet:namespace />editor.getHTML();

alert(x);
}

But it is showing that ReferenceError: _InterviewSchedule_WAR_InterviewScheduleportlet_initEditor is not defined error. How to resolve it and get the value in a javascript variable


thumbnail
Mohammad Azharuddin, modifié il y a 8 années.

RE: How to get the value of Liferay input editor in a javascript variable

Expert Publications: 492 Date d'inscription: 17/09/12 Publications récentes
<aui:form action="" method="post" name="fm" onsubmit="<%=&quot;event.preventDefault(); &quot;+ renderResponse.getNamespace() + &quot;saveContent();&quot;%>">
<liferay-ui:input-editor editorImpl="<%=EDITOR_WYSIWYG_IMPL_KEY%>" />
<aui:input name="editorContent" type="text">
<aui:button type="submit" value="submit" />
</aui:input></aui:form>


&lt;%!public static final String EDITOR_WYSIWYG_IMPL_KEY = "editor.wysiwyg.portal-web.docroot.html.view.jsp";%&gt;
<aui:script>
function <portlet:namespace />initEditor() {
		return "&lt;%=UnicodeFormatter.toString(editorContent)%&gt;";
	}
Liferay.provide(
		window,
		'<portlet:namespace />saveContent',
		function() {
alert(window.<portlet:namespace />editor.getHTML());
			document.<portlet:namespace />fm.<portlet:namespace />editorContent.value = window.<portlet:namespace />editor.getHTML();
		
		},
		['liferay-util-list-fields']
	);
	

</aui:script>
thumbnail
Jeet Chatterjee, modifié il y a 8 années.

RE: How to get the value of Liferay input editor in a javascript variable

Junior Member Publications: 33 Date d'inscription: 22/11/14 Publications récentes
can you use my code i am getting anything from your code
thumbnail
Liferay Dev, modifié il y a 8 années.

RE: How to get the value of Liferay input editor in a javascript variable

Junior Member Publications: 81 Date d'inscription: 17/05/15 Publications récentes
<portlet:actionURL name="updateJSONPayload" var="configUR" />


<div class="container" >
<div class="row-fluid">
<form name="<portlet:namespace />addContent" >
<div class="control-group">
<label class="control-label text-color" for="<portlet:namespace />subject">
Subject</label>
<input type="text" name="<portlet:namespace />subject" id="<portlet:namespace />subject" value="">
</div>
<div class="control-group">
<label class="control-label text-color" for="<portlet:namespace />Body">Body
</label>
<liferay-ui:input-editor />
<input name="<portlet:namespace />htmlCodeFromEditorPlacedHere" type="hidden" value="" />
</div>
<div class="text-center ">
<input class="btn btn-primary" type="button" value="Save" onClick="saveData()" />
</div>

</form>

</div>
</div>
<script>
function <portlet:namespace />initEditor(){
return "<%= UnicodeFormatter.toString("default content") %>";
}

function saveData()
{
var emailSubject=$('input[name="<portlet:namespace />subject"]').val();
var emailBody = window.<portlet:namespace />editor.getHTML();
$('input[name="<portlet:namespace />htmlCodeFromEditorPlacedHere"]').val(emailBody);
alert(emailSubject+"\n"+emailBody);

jQuery.ajax({
url : '<%=configUR%>',
data: {"<portlet:namespace/>htmlCodeFromEditorPlacedHere" : emailBody, "<portlet:namespace/>subject":emailSubject },
type: "POST",
dataType: "html",
success: function(data) {
$("#<portlet:namespace/>wait").hide();


}
});

}
</script>

In Java:
System.out.println("Subject----- "+ParamUtil.getString(actionRequest, "subject"));
System.out.println("Body-----\n "+ParamUtil.getString(actionRequest, "htmlCodeFromEditorPlacedHere"));