I have a problem with primefaces
dialog. I have custom validation.
I created javascript method to keep the dialog opened when custom validation fails.
But although validation fails, it keeps closing.
Here is my code:
function alertMsg()
{
var str1 = document.getElementById("templateForm:resultMsg").textContent;
var str2 = "Duplicate name.";
if(str1.localeCompare(str2) == 0)
{
alert("inside same!")
PF(dlg).show(); //Although i try to keep open, this dialog always close.
}
}
.....some code
<p:dialog header="Add" widgetVar="dlg" id="add" resizable="false" modal="true" closable="false" width="600px" >
<h:panelGrid columns="4" cellpadding="5" >
<p:outputLabel value="Name" style="width:130px;"/>
<p:outputLabel value=":" style="width:15px;"/>
<h:inputText id="Name" value="#{Bean.Name}" styleClass="form-control" style="width:300px;" required="true" requiredMessage="!" >
</h:inputText>
<h:outputText id="resultMsg1" value="Duplicate name." style="color:red; width:30px;"/>
</h:panelGrid>
<p:commandButton process="@parent" ajax="true" value="Save" onstart="alertMsg()"
update= templateForm:resultMsg" action="#{Bean.save()}" styleClass="btn btn-danger">
</p:commandButton>
</p:dialog>