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
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.
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
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).
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?
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.