I have a user object which is using pfc services. Now, during update, how can I make sure that a text field in datawindow is not empty?
3 Answers
PFC has a DataWindow Required Column service, that changes the behaviour of columns' Required attribute to evaluate at save time. If your requirement involves editmask columns, this won't work, but may be an easy way to achieve this otherwise.
To use this, I'd put the following code in the Constructor (warning: it's been a while since I've used it):
of_SetReqColumn(TRUE)
inv_reqcolumn.of_RegisterSkipColumn ("col_a")
Good luck,
Terry.
I will try to explain the method that I use in order to make sure that a user will not leave a specified field empty. The following is the code that I have put in the pfc_updateprep event of u_dw (the ancestor). Then, for each one of the columns that I want a value to be given in any case, I put an M
in the tag
property of the textfield that describes the column. HTH.
integer li_size,i,l,li_zero
string ls_textname,ls_tag,ls_objects[]
string ls_col,ls_type,ls_text,ls_key,ls_any
any la_null,la_any
dec ld_zero
real lr_zero
long ll_zero
boolean lb_zero
dwItemStatus l_status,l_key_status
This.Modify("DataWindow.Table.UpdateKeyinPlace=Yes")
li_size = This.inv_base.of_Getobjects(ls_objects[ ],"column","*",TRUE)
FOR l=1 TO This.Rowcount()
l_status=This.GetItemStatus(l, 0,Primary!)
IF l_status=NewModified! OR l_status=Datamodified! THEN
FOR i = 1 to li_size
ls_col=ls_objects[i]
ls_key = Upper(This.Describe(ls_col+".Key"))
ls_type=This.Describe ( ls_col + ".ColType")
ls_textname=ls_col+"_t" // because the textnames that I use are the same as the column names followed by a "_t"
ls_tag=This.Describe(ls_textname+".Tag")
ls_text=This.Describe(ls_textname+".Text")
IF ls_tag='M' THEN
lb_zero = FALSE
IF This.Rowcount()>0 THEN
la_null=This.inv_base.of_GetItemany(l,ls_col)
choose case Upper(MidA(ls_type,1,3))
case 'DEC'
ld_zero=Dec(la_null)
IF ld_zero = 0 THEN lb_zero=TRUE
case 'INT'
li_zero=Integer(la_null)
IF li_zero = 0 THEN lb_zero=TRUE
case 'REA'
lr_zero=Real(la_null)
IF lr_zero = 0 THEN lb_zero=TRUE
case 'LON'
ll_zero=Long(la_null)
IF ll_zero = 0 THEN lb_zero=TRUE
end choose
IF Isnull(la_null) OR lb_zero THEN
Messagebox(gnv_app.of_Getframe().Getactivesheet().Title,&
"You must provide a value for the following field ~r("+&
ls_text+") !!!")
Return FAILURE
END IF
END IF
END IF
NEXT
END IF
NEXT
Return SUCCESS
What I've done in PB is to set the following datawindow column properties to TRUE or checked:
- Empty string is NULL
- Required
If you do this, the datawindow should automatically validate the field for you and prevent the user from leaving the field blank.
[EDIT - Clarification after Terry's always good advice]
The first part of my post should work for text fields at data entry time and I believe will force the user to enter a valid value in the dw before allowing focus to change unless you modify that behavior, for example, in the itemchanged event.
The PFC Required Column service can be turned on and the column registered with it to provide save-time validation. This makes it less cumbersome for a user to move through the fields while navigating the fields, and only pesters the user when they try to save.