[Cuis-dev] validating text input

Mark Volkmann r.mark.volkmann at gmail.com
Sun Apr 6 09:50:15 PDT 2025


This looks interesting and quite useful! I'm thinking though that input
validation is such a common need that TextModelMorph should support it. I
think I've worked out the details of how it can be easily done. I tested my
approach by creating subclasses of TextModelMorph and InnerTextMorph, but
what I did in those subclasses could just as well go into their
superclasses. It would enable code like this in order to create a text
input that only accepts entry of an integer up to 5 characters. The
important parts are in red.

entry := TextModelMorph withText: ''
    acceptOnAny: true;
    hideScrollBarsIndefinitely;
    "Don't allow more than five characters."
    maxSize: 5;
    "Only allow digits."
    charValidationBlock: [ :char | char isDigit ];
    "Setting height to zero causes it to use minimum height for one line."
    morphExtent: 100 @ 0;
    "Don't allow the first character to be zero."
    valueValidationBlock: [ :value | value first ~= $0 ];
    wrapFlag: false.

If there is interest in this, I will provide a changeset. Otherwise I can
just use my custom subclasses.

On Sat, Apr 5, 2025 at 1:10 AM Hilaire Fernandes via Cuis-dev <
cuis-dev at lists.cuis.st> wrote:

> 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
>
> --
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st
> https://lists.cuis.st/mailman/listinfo/cuis-dev
>


-- 
R. Mark Volkmann
Object Computing, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20250406/58472253/attachment-0001.htm>


More information about the Cuis-dev mailing list