Trailing blank in text field and log module

Hy all. I am looking for some advice on the folloiwing topic.

As you are all aware database CHAR(10) is a fixed string of 10 chars.
This means that when such field is loaded from the database into a form field is always presented as a 10 char length string, regardless the actual number of alphanumeric chars (it’s padded with trailing blank up to 10 chars). For instance the string RED, is displayed in a form field as REDssssssssss where s is a single blank space.

The extra trailing blank are confusing the user when he has to modify the field.
For instance, when user replaces RED with GREEN on a web form, he has to backspace and delete all trailing blanks. Moreover the focus is always displayed by browser at the end of the field, not at the start, and this force user to delete all trailing blank.
To avoid the tyring and confusing deleting of trailing blank, the field may be trimmed on the OnLoad event, so RED is displayed on the form without useless trailing spaces.

This works perfectly unless you activate the log modole of SC in the form app.

Even if the user does not press any key, and simply save a record without touching the keyboard, Scriptace log module compares the DB original field (REDssssssssss) with the trimmed one (RED) and consider the missing trimmed blank as a modification of the record (which is in theory correct) and log such modification in the LogModule as soon as the user update the record.

The user complains because he/she has not done any actual modification of the record, it was just a trim of blank made in PHP inside OnLoad event, just for presentation purpose.

Any clue ?

One possibility would be to modify the AdoDB driver in order to remove trailing blank on fetched fields as soon as the field is read from DB and before is passed to SC. In such case there is no need to trim blank on the onLoad event and everythink works.
AdoDB drivers has a flag for Oracle database ( $ADODB_ANSI_PADDING_OFF) that actually does that but it works only for Oracle (I am using IBM DB2) and I dont think it’s a good idea to modify the AdoDB driver.

Hi, i think you must create a new field varchar(10) , and update this one with the value of other field. (without spaces). so your form can works with the new field.

1 Like

Thanks Alvaro for your suggestion.
It clearly works and it is also correct but … too expensive for me.

If I have 300 form apps against which I need to add the log module, and several of them contain text field which are trimmed for blanks in the OnLoad event.

I think the best approach would be to pass to SC the text fields already trimmed, avoiding to trim 'manually’in the OnLoad, so as far as SC is concerned no modification will be detected in the log.module.
The database will pad with blanks anyway all char field during insert/update.

I think you can modify your data type for your field to Varchar(10)

alter table my_table modify column myfield to myfeld vachar(10);

so your forms does not need modify them.

1 Like