[Cuis-dev] validating text input

Hilaire Fernandes hfern at free.fr
Fri Apr 4 23:09:53 PDT 2025


Hi Mark,

In the Cuis-Smalltalk-UI, you can find the Mold system a general system 
for input validation. It does not need to specialize Widget for 
validation, it uses external classes to do so.

  1
  2
  3
  4
  5
  6
  7
  8
  9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

	

MoldExample>>eight
"
MoldExample eight
"
  |mold fullname email confirmEmail |
	mold := Mold new.
	fullname := mold stringField
		on: #propertyValue of: ValueHolder new;
		label: 'Your Name';
		beRequired;
		addCondition: [:input | input includesSubString: ' ']
			labeled: 
				[:wrong | 
				'Please enter your first and last name. I couldn''t find a space in {1}' format:  {wrong} ].
	email := mold emailField
		on: #propertyValue of: ValueHolder new;
		label: 'Email Address:'.
	confirmEmail := mold emailField
		on: #propertyValue of: ValueHolder new;
		label: 'Confirm Email:'.
	email 
		addCondition: [:input | input = confirmEmail input ]
		labeled: 'Email addresses did not match.'.
	confirmEmail 
		addCondition: [:input | input = email input ]
		labeled: 'Email addresses did not match.'.
	mold textField
		on: #propertyValue of: ValueHolder new;
		label: 'About yourself.';
		beRequired.
	mold checkboxField
		on: #propertyValue of: (ValueHolder with: true);
		label: 'Sign for the newsletter';
		addCondition: [:input | fullname isValid not or: [input or: [fullname value first = $K ] ] ]
			labeled: 'Sorry, you may not opt out of our spam unless your name starts with K.'.
	mold openDialog: 'Example Eight'


Hilaire

-- 
http://mamot.fr/@drgeo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20250405/8ef1de49/attachment.htm>


More information about the Cuis-dev mailing list