Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
400 views
in Technique[技术] by (71.8m points)

javascript - How to validate an value submitted by a spinner

i am finishing off a web app, and want to put validation on my spinner, it should only let the user submit a value of between 1 and 50, however what i want is if a user deleted the value and for example entered 0, it to come up with a error message on the webpage informing the user that this is incorrect, the backing to the spinner has all validation, so if a value of 0 was entered, nothing would happen, but i am just looking for a way to inform the user about this, using a pop up etc

here is my code for the spinner

<h:body>
 <h:form id="myForm"> 
  <p>
   Number of copies (Max of 50) :
   <p:spinner id ="Copies" min="1" max="50" value="#{printerSettings.p}" size ="1"> 
   <!-- allows the user a choice of up to 50, this is more than enough for any situation, if needed this can be removed or raised -->
   <p:ajax update="p"/>
  </p:spinner>
  <div class="whiteSpace"/>   
  <h:outputText value="Copies that will be printed: &nbsp; #{printerSettings.p}" id="p"/>
 </p>

i have tried to add javascript validation to no success, as you can see in my other question

my question here is what is the best method of achieving my aim, and does any one have any examples i could follow ?

Thanks guys:)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try add this one:

<f:validateLongRange minimum="1" maximum="50" />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...