I need a PrimeFaces input component, to get/set an amount of cash, that means a Decimal with 2 digits after the floating point.
I tried using inputMask, like
<p:inputMask value="#{moneyBean.amount}" mask="999.99"/>
But I can't find some way to set a mask that accepts:
1 or more arithmetic values before floating point
Optionally, a floating point "."
0 to 2 arithmetic values after the floating point
For Example, some valid inputs would be:
1234.56
1234.5
2.8
120
120.00
Any ideas to get this input in an efficient way?
A regular expression was the best way I've found so far
<p:inputText id="numInput" value="#{val.value}" required="true"
label="#{val.title}" validatorMessage="Not valid Number">
<p:ajax event="change" process="#form" update=":edit_main" />
<f:validateRegex pattern="^[-+]?[0-9]*\.?[0-9]{1,2}+$" />
</p:inputText>
<p:message for="numInput" />
you can use Client Side Validation tag visit link
http://www.primefaces.org/showcase/ui/csvEvent.jsf
There are so may example that can help you.
i think your problem will be resolved by these two tag
<f:validateDoubleRange minimum="5.5" maximum="8.5" />
and
<p:clientValidator />
tell if not work.
Now i got exactly what you want. you want only two digit after "."
The Prime Faces extensions are provide such type of checks.
Go throw the link
http://www.primefaces.org/showcase-ext/sections/inputNumber/advanceUsage.jsf
it will sure help you.
Related
To get the numbers with decimal characters in keyboard of iOS, I tried almost every trick in js and jquery (tel as input type, 0.01 as step etc...) but the only solution was the plugins:
https://github.com/mrchandoo/cordova-plugin-decimal-keyboard
https://github.com/gbrits/cordova-plugin-ios-decimal-keyboard
https://www.npmjs.com/package/cordova-plugin-decimal-keyboard-wkwebview
...
They are all working. However...
If there are more than one input fields after each other and if you switch from a "non-decimal" field to our "decimal" input field (either by arrows or by just tapping with fingers), you don't see the decimal character anymore, but just the numbers. If you unclick/click on "Done" and select the decimal input field again, it works then again.
This is the common problem of all the plugins. I'm asking myself whether it is a known issue or it is a very specific problem of my case?
This is my html:
<input v-if="isIOS" type="text" pattern="[0-9]*" decimal="true" decimal-char=","
maxlength="10" min="0" :max="detailsSelectedPunt.tMax" placeholder="Punt..." v-model="detailsSelectedPunt.Number">
<input type="text" maxlength="255" placeholder="Commentaar..." v-model="detailsSelectedPunt.Commentaar">
<sjg:gridColumn name="orderLowPrice" title="Oder Low price" sortable="false" editable="true" edittype="text"/>
The above has to be a 7,4 decimal number basically with 3 digit max number and 4 decimal places.
how to set this rule in the grid column?
I do not have the libraries loaded, but JavaScript has some basic numeric formatting in place. use toPrecision(7) or toFixed(4) to obtain your desired results.
toPrecision(7) will only show 7 digits total (truncating if necessary)
toFixed(4) will only truncate the decimal to 4 digits.
I believe you can use formatter="formatNumber" in your column markup, and then the format function that it calls:
<sjg:gridColumn name="orderLowPrice"
title="Oder Low price"
sortable="false"
editable="true"
edittype="text"
formatter="formatNumber" />
...
<script>
function formatNumber(number){
return number.toFixed(4);
}
</script>
you can also reference here for more formatting information: https://code.google.com/p/struts2-jquery/wiki/FormatGrid
I have an input for telephone number.
I would like to write this format: 0175 6565 6262 (with spaces). But if write with " " spaces so get error and I write without spaces so get not error.
Here my HTML Input:
<input type="text" data-parsley-minlength="6" data-parsley-minlength-message="minlength six number" data-parsley-type="digits" data-parsley-type-message="only numbers" class="input_text" value="">
Hope someone can help me?
That's a great answer, but it's a bit too narrow for my needs. Input field should be tolerant of all potential inputs – periods, hyphens, parentheses, spaces in unexpected places, plus signs for international folk – and using this document from Microsoft detailing what numbers IE11 should accept, I've come up with this:
data-parsley-pattern="^[\d\+\-\.\(\)\/\s]*$"
Every number in that list passes the test with flying colours. Enjoy!
If you want your input to accept a string like "nnnn nnnn nnnn" you should use a regular expression.
For example, you can use the following HTML:
<input type="text" name="phone" value="" data-parsley-pattern="^\d{4} \d{4} \d{4}$" />
With this pattern the input will only be valid when you have fourdigits«space»fourdigits«space»fourdigits
You can test or tweak the regular expression and test it here: http://regexpal.com/
If you will use this pattern multiple times in your project I suggest you create a custom validator (see http://parsleyjs.org/doc/index.html#psly-validators-craft)
Currently i have a field that takes in a telephone number.
It performs a length validation without fail. What i really want is there to be length validation only when a value is input, and no validation when there is no value. How can i accomplish this?
<p:inputText id="corporateTel" label="#{labelResource.telephone}">
<f:validateLength minimum="5" maximum="20" />
</p:inputText>
This is already the default behaviour. Your problem is caused elsewhere. Perhaps you used an int instead of Integer or String, so that it defaults to 0 instead of null. Or perhaps you used an Integer while running the webapp on Tomcat/JBoss wherein the default Apache EL implementation would implicitly coerce it to 0 instead of null. You can turn it off by adding the following VM argument:
-Dorg.apache.el.COERCE_TO_ZERO=false
Or use String instead of Integer. This is also a more appropriate data type for phone numbers as they may have a leading 0 which would otherwise be chopped off when using Integer.
So stand alone I get what I need. But I want to truncate it, my dynamic text comes out with dirty text globbered with Microsoft Word garbage.
An Example :
≪! [If Gte Mso 9]>≪Xml> ≪Br /> ≪O:Office Document Settings> ≪Br /> ≪O:Allow Png/> ≪Br /> ≪/O:Off...
So how do I get the best of both worlds? Is there a shorthand ruby way to do this? For example a gsub statement that would clip off everything after the 125th char?
if you just want to slice, you can
>> long_ugly_string = "omg this is a long string"
=> "omg this is a long string"
>> long_ugly_string[10..-1]
=> "s a long string"
Reference: http://ruby-doc.org/core/classes/String.html#M000771
so, you are just specifying the starting character (10) and the ending character (-1 tells it to go to the end of the string).