Hello,
how would I implement validation for calculated fields?
AFAIK and tested value constraints only work if the user actually enters a value. But what about calculated fields. For example: Say we have three frields [a], [b] and [c]. [c] is calculated by [a] * [b]. Let's assume that [c] has a mask "nn.nn". Now If [a] and [b] are 10 the result is 100 but the editor displays "00.00".
Is there a way to either empty or display the correct calculated value?
RegardsJohannes
Hello Johannes,
Thank you for posting.
I have been looking into the provided description regarding the displayed value in the editor. On my side the value of the editor is correctly calculated and displayed. I had attached a sample project XamNumEditorCalculatedValues.zip where a mask “nn.nn” is set for the XamNumericEditor. The shown value when [a] is 10 and [b] is 5 is 50,00. Please note that when the mask for the editor is set, the number of displayed digits might be more than the mask allows. For example when you have [a] = 10 and [b] = 10, [c] should be 100,00 but the mask “nn.nn” allows only two digits before the floating point. In order to allow the whole value to be displayed, you could set the mask to “nnn.nn”.
If you have any questions, please feel free to let me know.
Hi Maria,
yes, if I have a value that fits into the mask the value is displayed correctly. That is not the problem though. The problem becomes apparent when a value is bigger then the mask.
In our case we cannot simply increase the mask because that might be configured on the customers side. We have no control over it. What we would like to have is a mechanism to tell the xamnumericeditor not to accept values that do not fit the configured mask.
Is there maybe an input constraint?
Johannes,
I understand your point. What I could suggest you here in order to change the value of the XamNumericEditor, if it not fits to the mask, is to hadle the loaded event of the control. This event could be used to check if the value is bigger than the one that is allowed by the mask and another value could be set (e.g. 0 or null).
Hello Maria,
It is hard to believe that there is no built in way to prevent this behavior. If that is not the case I would even consider this bug. In essence the editor is displaying wrong data. Can you please check with one of your developers if there is a build in way?
Thank you in advanceJohannes
Hi Johannes,
If the Mask property is “nn.nn”, the user would not be allowed to enter a number larger than 99.99. The Format property could be set in order to display “100.00” in the XamNumericEditor when it is first displayed (it is not in edit mode):
<Setter Property="Format" Value="N2"/>
Please note that when the editor goes into edit mode the mask will be applied and the value would be changed again so that it corresponds to the mask.
I hope this helps.
Maybe we can go another route. Is it possible to define a mask that only specifies decimal points? Like so: ".nn". This mask would then accept 1.54 and 1000000000.54.
A mask for the floating point input could be set using the {double:-i.f:c} mask characters. This will allow you to set the number of digits before the floating point – i, and the number of digits after the floating point – f. For example <Setter Property="Mask" Value="{}{double:9.2}"/>
Here more information on the available masks can be found: http://help.infragistics.com/Help/NetAdvantage/WPF/2012.1/CLR4.0/html/xamInputs_Masks.html
If you have any other questions, please do not hesitate to ask.
I am just checking if you have any other questions on the matter.
Hi,
When a mask is applied it affects the whole value in the XamNumericEditor. This means that if you need to display a larger number, you could apply a mask that allows larger number of digits before the floating point. If you need to keep the mask as it is, you could use the loaded event as I had suggested in one of my previous posts and change the value of the editor accordingly.
Thanks for the reply. However that is not exactly what I was hoping for. With your solution one would still have to specify the digits before the ".". As I mentioned, is it possible to only specify the decimal digits? So in your case only specify the "f" part.