ethanjyx
ethanjyx

Reputation: 2069

Primefaces how to erase validation fails in dialog when reopen the dialog

I have a required input field in a p:dialog. If firstly I submit nothing for the field, a validation error happens on that field. Then I close the dialog and reopen it, the validation error still exists. What can I do to eliminate the validation error when close the dialog?

Upvotes: 14

Views: 8833

Answers (3)

jansohn
jansohn

Reputation: 2326

You should use the p:resetInput on the element that you have to open the dialog.

For example if you use a p:commandButton

<p:commandButton value="Open dialog" update=":dialogId" oncomplete="PF('dialogWidget').show()" >
    <p:resetInput target=":dialogId" />
</p:commandButton>

This will reset the cached values (including the validation messages) upon opening the dialog.

Upvotes: 14

rbento
rbento

Reputation: 11608

I was able to reproduce your case and you could do the following:

  • Make your dialog closable="false".
  • Add a Cancel button that will hide the dialog.
  • Add a resetInput component from Primefaces Extensions inside your Cancel button. This will clear the form validations and values.

Here is an example that assumes your dialog as a widgetVar named wvDialog.

    <p:commandButton value="Cancel" immediate="true" onclick="wvDialog.hide()">
        <pe:resetInput for="myDialogFormId />
    </p:commandButton>

You could even call a bean method in the button actionListener if you need.

I hope it helps.

Upvotes: 3

Kishor Prakash
Kishor Prakash

Reputation: 8151

Update the p:dialog or p:message every time you submit the Form.
You can do that by using update attribute of p:commandButton.

<p:commandButton update="ID_OF_DIALOG" />

Upvotes: 0

Related Questions