Hi all,
I have some basic validation on an input field using the simpleTypes. Now, I want to do an extra check on the input data which cannot be done with regular expressions. I found the Custom Forms and Validation section in the Application Development Guide and I looked this up in the API Reference. But, I still don't get how I can make this extra check.
For instance this test case:
- The input is a zip code. The zip code is in the right format using the simpleType validation.
- I have a table that provides coordinates that correspond with the zip code.
- I want to calculate if the zip code entered is not more than 25 kilometers from my home.
- If it is more it should be validated as an invalid zip code, otherwise it should be valid.
Can someone please provide me with an example of how to do this? (NOTE: the above case is just an example.)
Thanks in advance,
Lesley

Additional check
3 July, 2008 - 17:05 — andysHi burger.lj.
Why dont you add extra behavior in your input-zipcode? This behavior might have an extra check on blur event (or any event that you like)
e.g if the input is valid zipCode then check whether it is more than 25 km from my home.
Hope it helps,
Andys
That sounds good
7 July, 2008 - 12:15 — burger.ljHi Andys,
That sounds good. But I still have one question: How does this behavior influence the validation? Because I want the behavior to check if (whatever it is validating) is valid and that I can still use the validation message. Now it would say "This is not a valid zip code" if the format is wrong. I want the message to say this message not only when the format is wrong, but also if the distance is invalid (by the behavior).
Is this possible? If so, how do I accomplish this?
Thanks,
Lesley
custom form validation
8 July, 2008 - 14:07 — andysHi burger.lj,
The behavior will influence the validation if we add our checking there and fire the errorMessage to be displayed and hide.
I will give an example code for this additional checking.
Case study:
Check if value is a valid number, then check whether the number is more than 25 or less than 25.
Step:
1. Create a behavior that will do the extra checking
<d:namespace name="http://www.backbase.com/2006/PersonalDevelopment">
<d:behavior name="distance">
<!-- add property errorMessage to save the reference to the message -->
<d:property name="errorMessage" />
<!-- add blur event, do extra validation on this event -->
<d:handler event="blur" type="application/javascript">
<![CDATA[
var input = this;
<!-- extra check only when the value is valid -->
if(input.getProperty('validity')){
var value = parseInt(input.getProperty('value'));
<!-- Get the messages -->
var msg = bb.document.getElementById("custom_validation_field");
var messages = msg.getProperty('messages');
var selectedMessage;
<!-- if value more than 25, show the error -->
if(value > 25){
for (var i = 0, length = messages.length; i < length; i++) {
if (messages[i].getProperty('event') == 'invalid') {
selectedMessage = messages[i];
this.setProperty("errorMessage", selectedMessage);
}
}
selectedMessage.show();
}
else{
var errorMessage = this.getProperty("errorMessage");
errorMessage.hide();
}
}
]]>
</d:handler>
</d:behavior>
</d:namespace>
</d:tdl>
2. Add extra bf:messages in your form which message inside will be displayed when the value is more than 25 (error)
<bf:messages id="custom_validation_field">
<bf:message event="invalid" class="errorMessage" facet="required">
<div>Should be less than 25 km</div>
</bf:message>
</bf:messages>
...
Hope this helps,
Andys
It works
24 July, 2008 - 12:28 — burger.ljHi Andys,
I got it working now.
You offered a part of the solution. The other part you can read in http://bdn.backbase.com/node/4680.
Thanks,
Lesley