Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset input fields without executing validation

I have a Facelets view as below:

<h:form id="f1">
<p:panelGrid id="p1" columns="2"> 
<p: inputText value="Distance Travelled::/><p:inputText value="#{airTransportUsage.distance}" immediate="true"
required="true" requiredMessage="Distance Travelled Field cannot be left blank.."
converterMessage="Distance Travelled must be a number"
validatorMessage="Distance Travelled must be a valid number.."
id="dis">
<f:validateLongRange minimum="1"/>
</p:inputText>
<p:commandButton value="Reset" action="#{airTransportUsage.reset}" update=":f1:p1" />
</p:panelGrid>
</h:form>

When the reset button is clicked, the corresponding method can never be executed due to validation. I can't use immediate="true" on my reset button as it creates some other problems.

like image 778
Basuz Avatar asked Sep 27 '12 10:09

Basuz


People also ask

How to reset field in html?

The <input type="reset"> defines a reset button which resets all form values to its initial values.

How to set reset button in JavaScript?

Disabling and enabling a reset button You can enable and disable buttons at run time by setting disabled to true or false ; in JavaScript this looks like btn. disabled = true or btn. disabled = false .

How do I reset form values?

reset() method restores a form element's default values. This method does the same thing as clicking the form's <input type="reset"> control. If a form control (such as a reset button) has a name or id of reset it will mask the form's reset method. It does not reset other attributes in the input, such as disabled .


1 Answers

This worked for me in PrimeFaces 5.3

<p:commandButton action="#{bean.reset()}" value="Reset" process="@this" update="@form" resetValues="true" />

You can probably replace the "@form" target of the update attribute to a specific component if you want.

like image 138
StanL Avatar answered Sep 30 '22 02:09

StanL