Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mask a not rendered field in JSF?

The thing is I want to know how to mask a field, that is not rendered when I load the page. For example: I have an h:inputText that only renders after the user do something.

If the input text is rendered=true when I load the page, its working fine, but I need the user to hit a button, and based on a condition, the application renders the inputText or not.

Here is jQuery code:

$('input[name*="preco"]').maskMoney({symbol:"R$",decimal:".",thousands:","});

Thanks a lot.

like image 940
David Palmeira Avatar asked Dec 07 '25 02:12

David Palmeira


1 Answers

Either just render the script conditionally as well:

<h:inputText ... rendered="#{some condition}" />
<h:outputScript rendered="#{some condition}">maskMoney()</h:outputScript>

or, if you're using a PrimeFaces command component, make use of PrimeFaces oncomplete:

<p:commandButton ... oncomplete="maskMoney()" />

or, if you're using <f:ajax>, make use of onevent:

<f:ajax ... onevent="function(data) { if (data.status == 'success') maskMoney() }" />
like image 149
BalusC Avatar answered Dec 08 '25 16:12

BalusC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!