Boost logo

Boost :

From: John Torjo (john.lists_at_[hidden])
Date: 2004-11-16 12:32:41


>
> Not really, there are two reasons why validation code is not necessary.
>
> 1. User validation always needs to be done by your business/process rules.
> -> When the 'go' event is generated, your app should validate the application variables (some of which will be connected to widgets). The validation will need to reset any variables which are in an out-of-bound condition (this implies that the GUI will need to re-synchronize to the new state of the variables). I wont comment on whether it is good to intertwine business logic within GUI update code....
>
> 2. Some widgets dont need validation eg: spinner, combobox, slider... These almost never need validation, since they are only ever populated with valid values.
>

I'm talking about your business logic.
Why shouldn't a combo-box / slider not have validation?

And as a side-note, combo-boxes can be "drop-down" as well. In which
case, you can :
- select from existing values
- enter a new value yourself

(which could require validation).

And as for validation, take an employee's data:

struct employee {
     std::string first_name;
     std::string last_name;
     int id;
     unsigned long salary;

     time_t birth_date;

     std::string country;
     std::string address;
     std::string email;

     bool has_homepage;
     std::string homepage;
};

Here are possible validations:
- First and last names should not be less than 4 chars
- ID should be within 10000 and 20000 range
- salary should not be bigger than 150,000
- birth_date should not be bigger than 1980
- email address should be valid
- homepage should be valid.

How do you handle those (and lets not remember user-friendlyness)?

And just for fun, try downloading win32gui, and run these examples:
examples/samples_dlg/simpl_empl_edit
examples/samples_dlg/simpl_empl_edit_bolded

, to see what I mean.

Best,
John

-- 
John Torjo,    Contributing editor, C/C++ Users Journal
-- "Win32 GUI Generics" -- generics & GUI do mix, after all
-- http://www.torjo.com/win32gui/
-- v1.5 - tooltips at your fingertips (work for menus too!)
    + bitmap buttons (work for MessageBox too!)
    + tab dialogs, hyper links, lite html

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk