Interface Validateable

 


Description

In BBj 5.0 and higher, a BBjControl implements the Validateable interface if it supports either the Control Validation Event or the ROWVALIDATION Notify Event.

Subinterfaces

None.

Implementing Classes

BBjCEdit, BBjCheckBox, BBjDataAwareGrid, BBjEditBox, BBjEditBoxSpinner, BBjListBox, BBjListButton, BBjListEdit, BBjInputD, BBjInputDSpinner, BBjInputE, BBjInputESpinner, BBjInputN, BBjInputNSpinner, BBjRadioButton, BBjStandardGrid, BBjTree

Methods of Validateable

Return Value

Method

void

accept(boolean valid)

string

getValidationText()

Example

rem ' Example for Validateable

rem ' Initialization
open (unt)"X0"
sysgui! = BBjAPI().getSysGui()
red! = sysgui!.makeColor(sysgui!.RED)
white! = sysgui!.makeColor(sysgui!.WHITE)

rem ' Window
window!= sysgui!.addWindow(100,100,500,350,"Validation Samples",$00010083$)
window!.setCallback(sysgui!.ON_CLOSE,"Close")

statbar!=window!.addStatusBar(100)

rem ' Controls and control validation
edit!=window!.addEditBox(101,20,20,90,25,"")
edit!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"TextValidation")

cedit!=window!.addCEdit(102,20,60,90,65,"Custom Edit",$8000$)
cedit!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"TextValidation")

inpute!=window!.addInputE(103,20,140,90,25,$$,32,"","InputE")
inpute!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"TextValidation")

inputn!=window!.addInputN(104,20,180,90,25,$$,"-###,###.00",$$,0,0)
inputn!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"InputnValidation")

inputd1!=window!.addInputD(105,20,220,90,25,$$,"",$$,0,0)
inputd1!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"InputdValidation")
inputd1!.setValue(jul(0,0,0))

inputd2!=window!.addInputD(106,20,260,90,25,$$,"",$$,0,0)
inputd2!.setValue(jul(0,0,0)-1)
inputd2!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"InputdValidation")

list$=$$
for letter=asc("A") to asc("Z")
   list$=list$+chr(letter)+$0a$
next letter

listbox!=window!.addListBox(108,140,20,90,100,list$)
listbox!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"ListValidation")

listbutton!=window!.addListButton(109,140,140,90,100,list$)
listbutton!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"ListValidation")

listedit!=window!.addListEdit(110,140,180,90,100,list$)
listedit!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"ListValidation")

radio1!=window!.addRadioButton(111,140,220,90,25,"One",$0020$)
radio1!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"RadioValidation")

radio2!=window!.addRadioButton(112,140,260,90,25,"Two",$0020$)
radio2!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"RadioValidation")

vector!=BBjAPI().makeVector()
vector!.addItem(radio1!)
vector!.addItem(radio2!)
window!.addRadioGroup(vector!)

check1!=window!.addCheckBox(113,260,20,50,25,"Grid",$0004$)
check1!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"GridCheckValidation")

check2!=window!.addCheckBox(114,260,140,50,25,"Tree",$0004$)
check2!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"TreeCheckValidation")

grid!=window!.addGrid(115,116,117,320,20,150,110,$81ce$,3,3)
grid!.setRowHeaderWidth(30)
grid!.setDefaultColumnWidth(30)
grid!.setRowHeight(20)
grid!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"GridValidation")

tree!=window!.addTree(118,320,140,150,145)
tree!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"TreeValidation")

dim music$[2,4]
music$[0,0]="The Beatles"
music$[0,1]="Hey Jude",MUSIC$[0,2]="Let It Be",MUSIC$[0,3]="Twist and Shout",MUSIC$[0,4]="Yesterday"
music$[1,0]="Paul Simon"
music$[1,1]="Bridge Over Troubled Waters",MUSIC$[1,2]="Hearts and Bones",MUSIC$[1,3]="Kathy's Song",MUSIC$[1,4]="The Sound of Silence"
music$[2,0]="Willie Nelson"
music$[2,1]="Always On My Mind",MUSIC$[2,2]="Getting Over You",MUSIC$[2,3]="Old Fords and Natural Stone",MUSIC$[2,4]="This Morning"

parent=0,node=1
tree!.setRoot(parent,"Music Tree")
for artist=0 to 2
   node=node+1
   tree!.addExpandableNode(node,parent,music$[artist,0])
   song_parent=node
   for song=1 TO 4
      node=node+1
      tree!.addNode(node,song_parent,music$[artist,song])
   next song
next artist

rem ' OK Button causes form validation

OK!=window!.addButton(1,380,300,90,25,"OK")
OK!.setCallback(sysgui!.ON_BUTTON_PUSH,"OK")
OK!.setCallback(sysgui!.ON_FORM_VALIDATION,"FormValidation")

rem ' Cancel Button suppresses all validation

Cancel!=window!.addButton(2,260,300,90,25,"Cancel")
Cancel!.setCallback(sysgui!.ON_BUTTON_PUSH,"Cancel")
Cancel!.setCausesControlValidation(0)

process_events

TextValidation:
text!=sysgui!.getLastEvent().getControl()
print "TextValidation: '"+text!.getValidationText()+"'"
valid=len(text!.getValidationText())
if valid
   text!.setBackColor(white!)
else
   text!.setBackColor(red!)
endif
text!.accept(valid)
return

InputnValidation:
print "InputnValidation: '"+inputn!.getValidationText()+"'"
valid=inputn!.getValue()
if valid
   inputn!.setBackColor(white!)
else
   inputn!.setBackColor(red!)
endif
inputn!.accept(valid)
return

InputdValidation:
inputd!=sysgui!.getLastEvent().getControl()
print "InputdValidation: '"+inputd!.getValidationText()+"'"
valid=0,today=jul(0,0,0),date=jul(inputd!.getValidationText(),err=InvalidDate)
valid=inputd!.isValid() and date>=today-366 and date<=today+366
InvalidDate:
if valid
   inputd!.setBackColor(white!)
   statbar!.setText("")
else
   inputd!.setBackColor(red!)
   statbar!.setText("Please enter a date within one year of today.")
endif
inputd!.accept(valid)
return

ListValidation:
list!=sysgui!.getLastEvent().getControl()
print "ListValidation: '"+list!.getValidationText()+"'"
valid=pos(list!.getValidationText()="AEIOU")
if valid
   list!.setBackColor(white!)
   statbar!.setText("")
else
   list!.setBackColor(red!)
   statbar!.setText("Please select a vowel from the list!")
endif
list!.accept(valid)
return

RadioValidation:
radio!=sysgui!.getLastEvent().getControl()
print "RadioValidation: '"+radio!.getValidationText()+"'"
print "Accept Radio Button: ",radio!.getText()
radio!.accept(1)
return

GridCheckValidation:
print "GridCheckValidation: '"+check1!.getValidationText()+"'"
grid!.setEnabled(check1!.isSelected())
check1!.accept(1)
return

TreeCheckValidation:
print "TreeCheckValidation: '"+check2!.getValidationText()+"'"
tree!.setEnabled(check2!.isSelected())
check2!.accept(1)
return

GridValidation:
print "GridValidation: '"+grid!.getValidationText()+"'"
grid!.accept(1)
return

TreeValidation:
print "TreeValidation: '"+tree!.getValidationText()+"'"
tree!.accept(1)
return

FormValidation:
control!=sysgui!.getLastEvent().getControl()
valid=0,valid=jul(inputd1!.getText(),err=*next)<=jul(inputd2!.getText(),err=*next)
if valid
   inputd1!.setBackColor(white!)
   inputd2!.setBackColor(white!)
   statbar!.setText("")
else
   inputd1!.setBackColor(red!)
   inputd2!.setBackColor(red!)
   statbar!.setText("Second date must be >= first date.")
endif
control!.accept(valid)
return

OK:
x = msgbox("Form validation was successful")
return

Cancel:
x = msgbox("The cancel button bypasses validation")
release

Close:
release

See Also

BBjAPI

BBjSysGui

BBjControl

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.



______________________________________________________________________________________

Copyright BASIS International Ltd. BBj®, Visual PRO/5®, PRO/5®, and BBx® are registered trademarks.