How to make a Spinner that only accepts numbers in Primefaces?

Asked

Viewed 426 times

3

I am using Primefaces for a college project. How do I make "Spinner" not accept "Characters" only numbers?

Idade:
<p:spinner id="spinnerBasic"  max="120" value="#{spinnerController.number1}"/>

1 answer

1


Good afternoon, you can solve this problem using javascript as below:

<script type="text/javascript">
   function onlyNumbers(data){
      data.value = data.value.replace(/[^0-9]/g,'');
   };
</script>

And in the spinner use (you can change the timing of the call if you like, using another type of event):

<p:spinner id="spinnerBasic"  max="120" value="#{spinnerController.number1}" onkeyup="onlyNumbers(this)" />

Browser other questions tagged

You are not signed in. Login or sign up in order to post.