掲示板
Alloy UI form
Hi,
I used aui:form
but
document.<portlet:namespace />fm.submit(); statement is not working
Help me, resolve this
thanks in advance
regards
Priyanka
I used aui:form
<aui:form action="<%=actionMethod%>" name="<portlet:namespace />fm" method="post">
<aui:button-row>
<aui:button type="submit" value="save" onClick="submitForm();" />
<aui:button value="cancel" />
</aui:button-row>
</aui:form>
<script type="text/javascript">
function submitForm() {
alert("In submit form");
document.<portlet:namespace />fm.submit();
}
</script>
but
document.<portlet:namespace />fm.submit(); statement is not working
Help me, resolve this
thanks in advance
regards
Priyanka
Hi..Priyanka
in place of name='<portlet:namespace />fm' use name="fm" only. just one change required. Keep all other things as it is. it will work.
in place of name='<portlet:namespace />fm' use name="fm" only. just one change required. Keep all other things as it is. it will work.
Hi Priyanka,
Try this below code
<aui:form action='<%=actionMethod%>' id='<portlet:namespace />fm' name='<portlet:namespace />fm'
method="post">
When ever your calling the script, you need to give form id.
Thanks & Regards,
Manasa.chandri.
Try this below code
<aui:form action='<%=actionMethod%>' id='<portlet:namespace />fm' name='<portlet:namespace />fm'
method="post">
When ever your calling the script, you need to give form id.
Thanks & Regards,
Manasa.chandri.
Hi Manasa,
Nope, not working.
You try to run this code:
Nope, not working.
You try to run this code:
<aui:form action="<%=actionMethod%>" name="<portlet:namespace />fm" id="<portlet:namespace />fm" method="post" onsubmit="xxx();">
<aui:button-row>
<aui:button value="save" onClick="<portlet:namespace />submitForm();" />
<aui:button value="cancel" />
</aui:button-row>
</aui:form>
<script type="text/javascript">
function submitForm() {
alert("In submit form");
document.<portlet:namespace />fm.submit();
}
function xxx() {
alert("going from xxx");
}
</script>
Hi Priyanka,
According to me your code is fine but it can be possible that the javascript function submitForm() could not be find.
So , You may do one thing that you can write your following lines of code(<script></script>) at the beginning of jsp page ..
<script type="text/javascript">
function submitForm() {
alert("In submit form");
document.<portlet:namespace />fm.submit();
}
</script>
Hope it will work for you,
Thanks & Regards,
Vishal R. Panchal
According to me your code is fine but it can be possible that the javascript function submitForm() could not be find.
So , You may do one thing that you can write your following lines of code(<script></script>) at the beginning of jsp page ..
<script type="text/javascript">
function submitForm() {
alert("In submit form");
document.<portlet:namespace />fm.submit();
}
</script>
Hope it will work for you,
Thanks & Regards,
Vishal R. Panchal
Priyanka :-
My First point is if you written
It will directly submit the form. Then what will be the difference between type="button" and type="submit"
Submit itself tells it will submit the form. Then what's the need of JavaScript function for it.
If you had written type="button" then you need to write javascript in order to submit the form.
And I don't think it matters what you write the name in the form. submit button will submit the form whatever the name will be.
I think you are missing something in making the action='<%=actionMethod%>'
Hope I am clear.
Regards,
Amit Doshi
<aui:form action='<%=actionMethod%>' name='<portlet:namespace />fm'
method="post">
<aui:button-row>
<aui:button type="submit" value="save" onClick="submitForm();" />
<aui:button value="cancel" />
</aui:button-row>
</aui:form >
<script type="text/javascript">
function submitForm() {
alert("In submit form");
document.<portlet:namespace />fm.submit();
}
</script>
My First point is if you written
<aui:button type="submit" value="save" onClick="submitForm();" />
It will directly submit the form. Then what will be the difference between type="button" and type="submit"
Submit itself tells it will submit the form. Then what's the need of JavaScript function for it.
If you had written type="button" then you need to write javascript in order to submit the form.
And I don't think it matters what you write the name in the form. submit button will submit the form whatever the name will be.
I think you are missing something in making the action='<%=actionMethod%>'
Hope I am clear.
Regards,
Amit Doshi
Hi Amit,
this is the code...
The actionURL is working without this document.<portlet:namespace />fm.submit(); containing function....i verified
but this statement is not getting executed
this is the code...
<portlet:actionurl var="actionMethod" name="actionMethod" />
<script type="text/javascript">
function submitForm() {
alert("In submit form");
document.<portlet:namespace />fm.submit();
}
function xxx() {
alert("going from xxx");
}
</script>
<aui:form action="<%=actionMethod%>" name="<portlet:namespace />fm" id="<portlet:namespace />fm" method="post" onsubmit="xxx();">
<aui:button-row>
<aui:button value="save" onClick="<portlet:namespace />submitForm();" />
<aui:button value="cancel" />
</aui:button-row>
</aui:form>
The actionURL is working without this document.<portlet:namespace />fm.submit(); containing function....i verified
but this statement is not getting executed
It will never run.
Here I am highlighting some of the point.
Because the name='<portlet:namespace />fm' which you have used in form will make internally something name of the form like _portletname_fm. Check the name of that form with the help of firebug.
And when you write javascript like
It will check for the form name like "<portlet:namespace />fm". As It is written in javascript. It will not automatically create portletnamespace for the portlet.
you have to pass that parameter from the javascript function.
And it will never get any form with the name like "<portlet:namespace />fm".
So you need to do something like this
Hope I am clear.
Thanks & Regards,
Amit Doshi
Here I am highlighting some of the point.
Because the name='<portlet:namespace />fm' which you have used in form will make internally something name of the form like _portletname_fm. Check the name of that form with the help of firebug.
And when you write javascript like
document.<portlet:namespace />fm.submit();
It will check for the form name like "<portlet:namespace />fm". As It is written in javascript. It will not automatically create portletnamespace for the portlet.
you have to pass that parameter from the javascript function.
And it will never get any form with the name like "<portlet:namespace />fm".
So you need to do something like this
<portlet:actionurl var="actionMethod" name="actionMethod" />
<script type="text/javascript">
function submitForm(portletnamespace) {
var frmname=portletnamespace+"fm";
alert("In submit form");
xxx();
document.frmname.submit();
}
function xxx() {
alert("going from xxx");
}
</script>
<aui:form action="<%=actionMethod%>" name="<portlet:namespace />fm" id="<portlet:namespace />fm" method="post">
<aui:button-row>
<aui:button value="save" onClick="submitForm('<portlet:namespace />');" />
<aui:button value="cancel" />
</aui:button-row>
</aui:form>
Hope I am clear.
Thanks & Regards,
Amit Doshi
Seems to work as per Amit's suggestion
However my problem is slightly different, in this code below, when the save button is clicked, the FormTestPortlet.addProduct method does not get executed.
<portlet:actionURL var="addProduct" name="addProduct" />
<script type="text/javascript">
function submitForm(portletnamespace) {
var frmname=portletnamespace+"fm";
alert("In submit form");
xxx();
}
function xxx() {
alert("going from xxx");
}
</script>
<aui:form action='<%=addProduct%>' name='<portlet:namespace />fm'
id='<portlet:namespace />fm' method="post" >
<aui:button-row>
<aui:button value="save" />
<aui:button value="cancel" onClick="submitForm('<portlet:namespace />');" />
</aui:button-row>
</aui:form>
Portlet class has :
public class FormTestPortlet extends MVCPortlet {
public void addProduct(ActionRequest request, ActionResponse response)
throws Exception {
System.out.println("Gauranga!!!");
}
}
portlet.xml has
<portlet-name>form-test</portlet-name>
<display-name>Form Test</display-name>
<portlet-class>com.test.FormTestPortlet</portlet-class>
<init-param>
<name>view-template</name>
<value>/html/formtest/view.jsp</value>
</init-param>
However my problem is slightly different, in this code below, when the save button is clicked, the FormTestPortlet.addProduct method does not get executed.
<portlet:actionURL var="addProduct" name="addProduct" />
<script type="text/javascript">
function submitForm(portletnamespace) {
var frmname=portletnamespace+"fm";
alert("In submit form");
xxx();
}
function xxx() {
alert("going from xxx");
}
</script>
<aui:form action='<%=addProduct%>' name='<portlet:namespace />fm'
id='<portlet:namespace />fm' method="post" >
<aui:button-row>
<aui:button value="save" />
<aui:button value="cancel" onClick="submitForm('<portlet:namespace />');" />
</aui:button-row>
</aui:form>
Portlet class has :
public class FormTestPortlet extends MVCPortlet {
public void addProduct(ActionRequest request, ActionResponse response)
throws Exception {
System.out.println("Gauranga!!!");
}
}
portlet.xml has
<portlet-name>form-test</portlet-name>
<display-name>Form Test</display-name>
<portlet-class>com.test.FormTestPortlet</portlet-class>
<init-param>
<name>view-template</name>
<value>/html/formtest/view.jsp</value>
</init-param>