s LearnSqueak.com

INPUTS, ACTIONS, AND LIVE OBJECTS

Build a form.
Make it respond.

Buttons, text input, a checkbox, a list, and a slider inside a real Squeak window.

In Morphic, a control is an object. It receives an event, sends a message to a model, and displays the result. This tutorial builds a small greeting form with five native controls and explains each connection.

9 runnable build stages11 new native screenshots14 event checks passedReal event recordingNo extra packages
Try the finished example

Run in the SqueakJS playground

The separate playground loads the real Smalltalk image on demand. This lesson keeps its native setup instructions; browser compatibility notes appear beside each demo.

01

Start with a button

This first example stands alone. Open Tools → Workspace, paste the whole block, select it, and choose do it. Click the green button. A Transcript opens and receives a line each time.

Workspace · select the complete block, then Do it
| button |
button := SimpleButtonMorph new.
button label: 'Say hello';
 target: [Transcript open; show: 'Hello from a button'; cr];
 actionSelector: #value;
 extent: 150@40;
 position: 100@100;
 openInWorld.
button
Download .st
REAL SQUEAK CAPTURESCREENSHOT
A real Squeak Say hello button
The button created by this snippet. Its action writes to Transcript.

target: identifies the receiver. actionSelector: names the message to send. Here the receiver is a block, so #value runs it. A selector is a Symbol, not a method call: the button sends it later. Keep event handlers short; a long synchronous loop can freeze the interface.

Remove the button using its halo’s red delete handle. Do not confuse the button’s target with its owner: the owner contains it visually, while the target receives its action.

02

Install the form model

The remaining examples share LearnSqueakFormDemo, a subclass of Model. It stores the name, checkbox state, selected list index, slider value, and output. Copy the complete setup below into a Workspace and Do it once. Then run the short opener.

Use a learning image. Check that the class name does not belong to your existing work. Re-running setup replaces this tutorial class’s methods. Squeak may ask for author initials when compiling for the first time.

Show complete runnable setup
Workspace · select the complete block, then Do it
Model subclass: #LearnSqueakFormDemo
 instanceVariableNames: 'name loud choice level result inputMorph sliderMorph'
 classVariableNames: ''
 poolDictionaries: ''
 category: 'LearnSqueak-Forms'.
(Smalltalk at: #LearnSqueakFormDemo) compile: 'initialize
 super initialize.
 self resetState'.
(Smalltalk at: #LearnSqueakFormDemo) compile: 'nameText
 ^ name'.
(Smalltalk at: #LearnSqueakFormDemo) compile: 'acceptName: aText
 name := aText asString withBlanksTrimmed.
 self changed: #nameText.
 ^ true'.
(Smalltalk at: #LearnSqueakFormDemo) compile: 'loud
 ^ loud'.
(Smalltalk at: #LearnSqueakFormDemo) compile: 'loudLabel
 ^ ''UPPERCASE greeting'' '.
(Smalltalk at: #LearnSqueakFormDemo) compile: 'toggleLoud
 loud := loud not.
 self changed: #loud'.
(Smalltalk at: #LearnSqueakFormDemo) compile: 'choices
 ^ #(''Hello'' ''Welcome'' ''Good morning'')'.
(Smalltalk at: #LearnSqueakFormDemo) compile: 'choice
 ^ choice'.
(Smalltalk at: #LearnSqueakFormDemo) compile: 'choice: anIndex
 choice := anIndex.
 self changed: #choice'.
(Smalltalk at: #LearnSqueakFormDemo) compile: 'level: aNumber
 level := aNumber rounded.
 result := ''Slider value: '', level printString.
 self changed: #result'.
(Smalltalk at: #LearnSqueakFormDemo) compile: 'result
 ^ result'.
(Smalltalk at: #LearnSqueakFormDemo) compile: 'greet
 | greeting |
 name isEmpty ifTrue: [result := ''Please enter a name.'' . self changed: #result. ^ self].
 greeting := (self choices at: (choice max: 1)), '', '', name, ''.''.
 result := loud ifTrue: [greeting asUppercase] ifFalse: [greeting].
 self changed: #result'.
(Smalltalk at: #LearnSqueakFormDemo) compile: 'open
 | window label input output button check list slider reset |
window := SystemWindow new.
window setLabel: ''LearnSqueak - Form controls''.
window model: self.
label := StringMorph contents: ''Name (press Enter to accept):''.
window addMorph: label frame: (0.04@0.03 corner: 0.96@0.10).
input := PluggableTextMorph on: self text: #nameText accept: #acceptName:.
input acceptOnCR: true; wrapFlag: false.
self inputMorph: input.
window addMorph: input frame: (0.04@0.11 corner: 0.96@0.23).
output := PluggableTextMorph on: self text: #result accept: nil.
output readOnly: true.
window addMorph: output frame: (0.04@0.73 corner: 0.96@0.95).
button := SimpleButtonMorph new.
button label: ''Greet''; target: self; actionSelector: #greet.
window addMorph: button frame: (0.66@0.55 corner: 0.79@0.67).
check := PluggableCheckBoxMorph on: self
    getState: #loud action: #toggleLoud label: #loudLabel.
check installButton.
window addMorph: check frame: (0.04@0.26 corner: 0.96@0.35).
list := PluggableListMorph on: self
    list: #choices selected: #choice changeSelected: #choice:.
window addMorph: list frame: (0.04@0.38 corner: 0.60@0.66).
slider := SimpleSliderMorph new.
slider target: self; actionSelector: #level:;
    minVal: 0; maxVal: 100; adjustToValue: 50.
self sliderMorph: slider.
window addMorph: slider frame: (0.66@0.40 corner: 0.94@0.50).
reset := SimpleButtonMorph new.
reset label: ''Reset''; target: self; actionSelector: #reset.
window addMorph: reset frame: (0.82@0.55 corner: 0.96@0.67).
window openInWorld; extent: 650@420; position: 300@150.
 ^ window'.
(Smalltalk at: #LearnSqueakFormDemo) compile: 'resetState
 name := ''Ada''. loud := false. choice := 1. level := 50.
 result := ''Change the controls, then click Greet.'' '.
(Smalltalk at: #LearnSqueakFormDemo) compile: 'inputMorph: aMorph
 inputMorph := aMorph'.
(Smalltalk at: #LearnSqueakFormDemo) compile: 'sliderMorph: aMorph
 sliderMorph := aMorph'.
(Smalltalk at: #LearnSqueakFormDemo) compile: 'reset
 self resetState.
 inputMorph ifNotNil: [inputMorph setText: name].
 sliderMorph ifNotNil: [sliderMorph adjustToValue: level].
 self changed: #nameText; changed: #loud;
     changed: #choice; changed: #result'.
Download .st
Workspace · select the complete block, then Do it
LearnSqueakFormDemo new open
Download .st
REAL SQUEAK CAPTUREGIF WALKTHROUGH
The Squeak form with text, checkbox, list, slider, output and Greet button
Recorded mouse and keyboard interaction: accept a name, change options, greet, drag the slider, validate empty input, and reset. Play is opt-in; Stop restores the still image.

Enter a name and press Enter to accept it before clicking Greet. Pick a greeting, optionally enable uppercase, and click Greet. Drag the slider’s narrow thumb to report a number. These web controls only play a recording; run the code in Squeak to use the form.

CONTAINER → CONTROLS → EVENTS → VALIDATION

Build the form in nine small stages.

Run the complete model setup above once. We reuse that installed model while constructing its window a control at a time. The short visible blocks explain the new lines; each checkpoint also provides a complete runnable version.

  1. Open Tools → Workspace.
  2. Copy one complete stage, select all of it, and choose do it, usually Ctrl+D / Cmd+D.
  3. Compare the result with its native screenshot. Close that window before running the next stage.

Every stage creates a fresh window. Temporary variables from one evaluation do not survive into another. Do not run a short excerpt by itself or paste it below an earlier complete stage. Stages 1–2 are independent of the model; stages 3–9 require the setup. The examples use native Squeak controls, not HTML form elements.

01

BUILD THE FORM STEP BY STEP

Create the form container

A SystemWindow contains the form. Open it before applying its final extent, because opening can apply an initial size. Nothing will receive text or clicks until we add controls.

Complete stage 1 · Workspace Do it
| window model label input output button check list slider reset |
window := SystemWindow new.
window setLabel: 'LearnSqueak - Form controls'.
window openInWorld; extent: 650@420; position: 300@150.
window
Download complete stage .st
REAL SQUEAK CAPTUREBUILD STEP 1
Form construction step 1: Empty native SystemWindow with a title and a content area.
Empty native SystemWindow with a title and a content area.

The 650@420 extent is width and height in pixels. The 300@150 position is relative to Squeak’s world. The title bar and close control come from SystemWindow; the blank interior is the area we will lay out.

02

BUILD THE FORM STEP BY STEP

Add a visible field label

The field label is a lightweight StringMorph. Create it, then make the window its visual owner using a relative frame.

Changed lines · included in complete stage 2
label := StringMorph contents: 'Name (press Enter to accept):'.
window addMorph: label
    frame: (0.04@0.03 corner: 0.96@0.10).
Show the complete runnable stage 2
Complete stage 2 · Workspace Do it
| window model label input output button check list slider reset |
window := SystemWindow new.
window setLabel: 'LearnSqueak - Form controls'.
label := StringMorph contents: 'Name (press Enter to accept):'.
window addMorph: label frame: (0.04@0.03 corner: 0.96@0.10).
window openInWorld; extent: 650@420; position: 300@150.
window
Download complete stage .st
REAL SQUEAK CAPTUREBUILD STEP 2
Form construction step 2: A StringMorph label is now owned by the window.
A StringMorph label is now owned by the window.

The rectangle uses fractions of the content area. Left 0.04 and right 0.96 leave margins; top 0.03 and bottom 0.10 reserve a short row. A label is not an input field and has no acceptance callback. Adding a Morph is separate from creating one.

03

BUILD THE FORM STEP BY STEP

Add the editable name field

Create a model, attach it to the window, and connect the text editor to a getter and acceptance selector. Enter accepts the current buffer; clicking somewhere else is not our form’s submit action.

Changed lines · included in complete stage 3
model := LearnSqueakFormDemo new.
window model: model.
input := PluggableTextMorph on: model
    text: #nameText accept: #acceptName:.
input acceptOnCR: true; wrapFlag: false.
model inputMorph: input.
window addMorph: input
    frame: (0.04@0.11 corner: 0.96@0.23).
Show the complete runnable stage 3
Complete stage 3 · Workspace Do it
| window model label input output button check list slider reset |
window := SystemWindow new.
window setLabel: 'LearnSqueak - Form controls'.
model := LearnSqueakFormDemo new.
window model: model.
label := StringMorph contents: 'Name (press Enter to accept):'.
window addMorph: label frame: (0.04@0.03 corner: 0.96@0.10).
input := PluggableTextMorph on: model text: #nameText accept: #acceptName:.
input acceptOnCR: true; wrapFlag: false.
model inputMorph: input.
window addMorph: input frame: (0.04@0.11 corner: 0.96@0.23).
window openInWorld; extent: 650@420; position: 300@150.
window
Download complete stage .st
REAL SQUEAK CAPTUREBUILD STEP 3
Form construction step 3: The editable field reads its initial Ada value from the model.
The editable field reads its initial Ada value from the model.

#nameText asks the model for the stored name. #acceptName: receives the edited Text when accepted. Its colon means one argument. The setter converts Text to String, trims surrounding spaces, and returns true to accept the change:

Installed model method · read or edit in the Browser
acceptName: aText
    name := aText asString withBlanksTrimmed.
    self changed: #nameText.
    ^ true

The model keeps inputMorph only so Reset can deliberately discard an unaccepted draft later. It is not needed for ordinary typing. The editor buffer and accepted model value are different states; this distinction is the source of many form bugs.

04

BUILD THE FORM STEP BY STEP

Add a read-only result pane

Use another PluggableTextMorph for output. It reads #result, has no acceptance selector, and is read-only. At this stage the complete snippet starts with the instructional message; the capture shows a test after accepting Grace and invoking the model’s greeting.

Changed lines · included in complete stage 4
output := PluggableTextMorph on: model
    text: #result accept: nil.
output readOnly: true.
window addMorph: output
    frame: (0.04@0.73 corner: 0.96@0.95).
Show the complete runnable stage 4
Complete stage 4 · Workspace Do it
| window model label input output button check list slider reset |
window := SystemWindow new.
window setLabel: 'LearnSqueak - Form controls'.
model := LearnSqueakFormDemo new.
window model: model.
label := StringMorph contents: 'Name (press Enter to accept):'.
window addMorph: label frame: (0.04@0.03 corner: 0.96@0.10).
input := PluggableTextMorph on: model text: #nameText accept: #acceptName:.
input acceptOnCR: true; wrapFlag: false.
model inputMorph: input.
window addMorph: input frame: (0.04@0.11 corner: 0.96@0.23).
output := PluggableTextMorph on: model text: #result accept: nil.
output readOnly: true.
window addMorph: output frame: (0.04@0.73 corner: 0.96@0.95).
window openInWorld; extent: 650@420; position: 300@150.
window
Download complete stage .st
REAL SQUEAK CAPTUREBUILD STEP 4
Form construction step 4: The output pane is connected. This test capture follows accepting Grace and sending greet to the model.
The output pane is connected. This test capture follows accepting Grace and sending greet to the model.

A model change alone does not necessarily update a view. The model announces self changed: #result after changing its output. The bound pane then asks for the new result. We add a visible action for this next.

05

BUILD THE FORM STEP BY STEP

Connect the Greet button

A button needs a label, a receiver, and a selector. It already knows how to process mouse press and release, so we do not write low-level mouse-event code.

Changed lines · included in complete stage 5
button := SimpleButtonMorph new.
button label: 'Greet';
    target: model;
    actionSelector: #greet.
window addMorph: button
    frame: (0.66@0.55 corner: 0.79@0.67).
Show the complete runnable stage 5
Complete stage 5 · Workspace Do it
| window model label input output button check list slider reset |
window := SystemWindow new.
window setLabel: 'LearnSqueak - Form controls'.
model := LearnSqueakFormDemo new.
window model: model.
label := StringMorph contents: 'Name (press Enter to accept):'.
window addMorph: label frame: (0.04@0.03 corner: 0.96@0.10).
input := PluggableTextMorph on: model text: #nameText accept: #acceptName:.
input acceptOnCR: true; wrapFlag: false.
model inputMorph: input.
window addMorph: input frame: (0.04@0.11 corner: 0.96@0.23).
output := PluggableTextMorph on: model text: #result accept: nil.
output readOnly: true.
window addMorph: output frame: (0.04@0.73 corner: 0.96@0.95).
button := SimpleButtonMorph new.
button label: 'Greet'; target: model; actionSelector: #greet.
window addMorph: button frame: (0.66@0.55 corner: 0.79@0.67).
window openInWorld; extent: 650@420; position: 300@150.
window
Download complete stage .st
REAL SQUEAK CAPTUREBUILD STEP 5
Form construction step 5: Greet now has its own button and action selector.
Greet now has its own button and action selector.

Type Grace, press Enter, then click Greet. You should see Hello, Grace. The selector #greet has no colon because the action needs no argument. A click reads the already accepted name; it does not implicitly accept pending edits.

Installed model method · shown in full
greet
    | greeting |
    name isEmpty ifTrue: [
        result := 'Please enter a name.'.
        self changed: #result.
        ^ self].
    greeting := (self choices at: (choice max: 1)), ', ', name, '.'.
    result := loud ifTrue: [greeting asUppercase] ifFalse: [greeting].
    self changed: #result
  1. The button sends greet to its target.
  2. The model validates the accepted name.
  3. It builds the result using its current greeting choice and uppercase flag.
  4. changed: #result tells the output view to refresh.

The model already has default values for the checkbox and list, even though those controls have not been added yet. Repeated Greet clicks with unchanged state produce the same output.

06

BUILD THE FORM STEP BY STEP

Add the checkbox state

A checkbox reads a Boolean and sends a toggle action. In this Squeak image, the pluggable wrapper needs installButton to create its inner checkbox.

Changed lines · included in complete stage 6
check := PluggableCheckBoxMorph on: model
    getState: #loud action: #toggleLoud label: #loudLabel.
check installButton.
window addMorph: check
    frame: (0.04@0.26 corner: 0.96@0.35).
Installed model method
toggleLoud
    loud := loud not.
    self changed: #loud
Show the complete runnable stage 6
Complete stage 6 · Workspace Do it
| window model label input output button check list slider reset |
window := SystemWindow new.
window setLabel: 'LearnSqueak - Form controls'.
model := LearnSqueakFormDemo new.
window model: model.
label := StringMorph contents: 'Name (press Enter to accept):'.
window addMorph: label frame: (0.04@0.03 corner: 0.96@0.10).
input := PluggableTextMorph on: model text: #nameText accept: #acceptName:.
input acceptOnCR: true; wrapFlag: false.
model inputMorph: input.
window addMorph: input frame: (0.04@0.11 corner: 0.96@0.23).
output := PluggableTextMorph on: model text: #result accept: nil.
output readOnly: true.
window addMorph: output frame: (0.04@0.73 corner: 0.96@0.95).
button := SimpleButtonMorph new.
button label: 'Greet'; target: model; actionSelector: #greet.
window addMorph: button frame: (0.66@0.55 corner: 0.79@0.67).
check := PluggableCheckBoxMorph on: model
    getState: #loud action: #toggleLoud label: #loudLabel.
check installButton.
window addMorph: check frame: (0.04@0.26 corner: 0.96@0.35).
window openInWorld; extent: 650@420; position: 300@150.
window
Download complete stage .st
REAL SQUEAK CAPTUREBUILD STEP 6
Form construction step 6: The native checkbox is installed and reads the Boolean model state.
The native checkbox is installed and reads the Boolean model state.

Tick UPPERCASE greeting, then click Greet again. The checkbox changes the flag; Greet decides when to rebuild the output. The label comes from loudLabel, and loud supplies its current state. Never treat a drawn checkmark as your application’s source of truth. This checkbox refreshes from the model during its stepping cycle, so an external reset may appear after a brief refresh.

07

BUILD THE FORM STEP BY STEP

Add the selectable greeting list

The list gets its items from one selector and reports a selected index through another. A fresh model starts at index 1, Hello.

Changed lines · included in complete stage 7
list := PluggableListMorph on: model
    list: #choices selected: #choice changeSelected: #choice:.
window addMorph: list
    frame: (0.04@0.38 corner: 0.60@0.66).
Installed model getter
choices
    ^ #('Hello' 'Welcome' 'Good morning')
Installed model setter
choice: anIndex
    choice := anIndex.
    self changed: #choice
Show the complete runnable stage 7
Complete stage 7 · Workspace Do it
| window model label input output button check list slider reset |
window := SystemWindow new.
window setLabel: 'LearnSqueak - Form controls'.
model := LearnSqueakFormDemo new.
window model: model.
label := StringMorph contents: 'Name (press Enter to accept):'.
window addMorph: label frame: (0.04@0.03 corner: 0.96@0.10).
input := PluggableTextMorph on: model text: #nameText accept: #acceptName:.
input acceptOnCR: true; wrapFlag: false.
model inputMorph: input.
window addMorph: input frame: (0.04@0.11 corner: 0.96@0.23).
output := PluggableTextMorph on: model text: #result accept: nil.
output readOnly: true.
window addMorph: output frame: (0.04@0.73 corner: 0.96@0.95).
button := SimpleButtonMorph new.
button label: 'Greet'; target: model; actionSelector: #greet.
window addMorph: button frame: (0.66@0.55 corner: 0.79@0.67).
check := PluggableCheckBoxMorph on: model
    getState: #loud action: #toggleLoud label: #loudLabel.
check installButton.
window addMorph: check frame: (0.04@0.26 corner: 0.96@0.35).
list := PluggableListMorph on: model
    list: #choices selected: #choice changeSelected: #choice:.
window addMorph: list frame: (0.04@0.38 corner: 0.60@0.66).
window openInWorld; extent: 650@420; position: 300@150.
window
Download complete stage .st
REAL SQUEAK CAPTUREBUILD STEP 7
Form construction step 7: A three-item list reports a one-based selected index.
A three-item list reports a one-based selected index.

Choose Welcome, then click Greet. With Grace accepted and uppercase enabled, the output becomes WELCOME, GRACE. Smalltalk collection indices are one-based. Zero means no selection; the greeting uses at least index 1 as its fallback. #choice: receives an index, not the displayed string.

08

BUILD THE FORM STEP BY STEP

Add the numeric slider

The slider sends one numeric argument whenever its thumb moves. It maps the internal 0–1 position onto the configured 0–100 range.

Changed lines · included in complete stage 8
slider := SimpleSliderMorph new.
slider target: model; actionSelector: #level:;
    minVal: 0; maxVal: 100; adjustToValue: 50.
model sliderMorph: slider.
window addMorph: slider
    frame: (0.66@0.40 corner: 0.94@0.50).
Installed model callback
level: aNumber
    level := aNumber rounded.
    result := 'Slider value: ', level printString.
    self changed: #result
Show the complete runnable stage 8
Complete stage 8 · Workspace Do it
| window model label input output button check list slider reset |
window := SystemWindow new.
window setLabel: 'LearnSqueak - Form controls'.
model := LearnSqueakFormDemo new.
window model: model.
label := StringMorph contents: 'Name (press Enter to accept):'.
window addMorph: label frame: (0.04@0.03 corner: 0.96@0.10).
input := PluggableTextMorph on: model text: #nameText accept: #acceptName:.
input acceptOnCR: true; wrapFlag: false.
model inputMorph: input.
window addMorph: input frame: (0.04@0.11 corner: 0.96@0.23).
output := PluggableTextMorph on: model text: #result accept: nil.
output readOnly: true.
window addMorph: output frame: (0.04@0.73 corner: 0.96@0.95).
button := SimpleButtonMorph new.
button label: 'Greet'; target: model; actionSelector: #greet.
window addMorph: button frame: (0.66@0.55 corner: 0.79@0.67).
check := PluggableCheckBoxMorph on: model
    getState: #loud action: #toggleLoud label: #loudLabel.
check installButton.
window addMorph: check frame: (0.04@0.26 corner: 0.96@0.35).
list := PluggableListMorph on: model
    list: #choices selected: #choice changeSelected: #choice:.
window addMorph: list frame: (0.04@0.38 corner: 0.60@0.66).
slider := SimpleSliderMorph new.
slider target: model; actionSelector: #level:;
    minVal: 0; maxVal: 100; adjustToValue: 50.
model sliderMorph: slider.
window addMorph: slider frame: (0.66@0.40 corner: 0.94@0.50).
window openInWorld; extent: 650@420; position: 300@150.
window
Download complete stage .st
REAL SQUEAK CAPTUREBUILD STEP 8
Form construction step 8: A numeric slider adds continuous input to the same model.
A numeric slider adds continuous input to the same model.

Drag the narrow thumb. Unlike the checkbox/list, the slider immediately changes the output text. adjustToValue: positions the thumb using 0–100 units without sending the action; setValue: uses 0–1 and sends the callback. The model retains the slider reference to restore 50 during Reset. Do not confuse these scales.

09

BUILD THE FORM STEP BY STEP

Add Reset and finish the form

A second action button restores the complete form, including an unaccepted text draft. This is intentionally a discard action, not a submit action.

Changed lines · included in complete stage 9
reset := SimpleButtonMorph new.
reset label: 'Reset'; target: model; actionSelector: #reset.
window addMorph: reset
    frame: (0.82@0.55 corner: 0.96@0.67).
Installed model reset method
reset
    self resetState.
    inputMorph ifNotNil: [inputMorph setText: name].
    sliderMorph ifNotNil: [sliderMorph adjustToValue: level].
    self changed: #nameText; changed: #loud;
        changed: #choice; changed: #result
Installed model defaults
resetState
    name := 'Ada'. loud := false. choice := 1. level := 50.
    result := 'Change the controls, then click Greet.'
Show the complete runnable stage 9
Complete stage 9 · Workspace Do it
| window model label input output button check list slider reset |
window := SystemWindow new.
window setLabel: 'LearnSqueak - Form controls'.
model := LearnSqueakFormDemo new.
window model: model.
label := StringMorph contents: 'Name (press Enter to accept):'.
window addMorph: label frame: (0.04@0.03 corner: 0.96@0.10).
input := PluggableTextMorph on: model text: #nameText accept: #acceptName:.
input acceptOnCR: true; wrapFlag: false.
model inputMorph: input.
window addMorph: input frame: (0.04@0.11 corner: 0.96@0.23).
output := PluggableTextMorph on: model text: #result accept: nil.
output readOnly: true.
window addMorph: output frame: (0.04@0.73 corner: 0.96@0.95).
button := SimpleButtonMorph new.
button label: 'Greet'; target: model; actionSelector: #greet.
window addMorph: button frame: (0.66@0.55 corner: 0.79@0.67).
check := PluggableCheckBoxMorph on: model
    getState: #loud action: #toggleLoud label: #loudLabel.
check installButton.
window addMorph: check frame: (0.04@0.26 corner: 0.96@0.35).
list := PluggableListMorph on: model
    list: #choices selected: #choice changeSelected: #choice:.
window addMorph: list frame: (0.04@0.38 corner: 0.60@0.66).
slider := SimpleSliderMorph new.
slider target: model; actionSelector: #level:;
    minVal: 0; maxVal: 100; adjustToValue: 50.
model sliderMorph: slider.
window addMorph: slider frame: (0.66@0.40 corner: 0.94@0.50).
reset := SimpleButtonMorph new.
reset label: 'Reset'; target: model; actionSelector: #reset.
window addMorph: reset frame: (0.82@0.55 corner: 0.96@0.67).
window openInWorld; extent: 650@420; position: 300@150.
window
Download complete stage .st
REAL SQUEAK CAPTUREBUILD STEP 9
Form construction step 9: The final form includes Reset, ready to discard a draft and restore defaults.
The final form includes Reset, ready to discard a draft and restore defaults.

setText: replaces the editor buffer and clears its unaccepted-edit flag. Without that explicit step, the view could retain a draft while the model had already reset. The list/output use change notifications; the plain slider needs an explicit thumb update. Press Reset twice: the state remains the same.

All frames are fractions of the window’s content area, so controls move together on resize. The 0.03 gap between Greet’s right edge and Reset’s left edge keeps them separate. This simple layout has no sophisticated minimum-size policy; keep it large enough for legible labels. More elaborate tools may benefit from a dedicated view class and ToolBuilder.

10

Exercise validation, repeated actions, and reset

Use the finished form, or simply run LearnSqueakFormDemo new open after setup. Try these cases in order:

  1. Type Grace but do not press Enter. Greet still uses the previously accepted name.
  2. Press Enter, select Welcome, enable uppercase, and click Greet twice. Both results should be WELCOME, GRACE.
  3. Drag the slider and check that a numeric value appears immediately.
  4. Delete the name, press Enter, then click Greet. A blank or spaces-only accepted name produces Please enter a name.
  5. Type an unaccepted draft and press Reset. The draft is discarded; Ada, Hello, unchecked uppercase, slider50, and the original prompt return.
  6. Click Greet again: Hello, Ada. Reset twice to verify repeatability.
Blank accepted name produces Please enter a name
Actual native validation result for a spaces-only accepted name.
Reset restores Ada and the default controls
Actual native reset state. The checkbox refreshes on its normal stepping cycle.

The automated version exercises the real text acceptance and slider callbacks as well as model actions, and always closes its test window. After setup, run the whole block with Print it. It answers '14 form event checks passed'; a failure names the broken behavior.

Show the complete form event checks
After setup · Workspace Print it
| window model input slider check count |
count := 0.
check := [:condition :message |
    condition ifFalse: [self error: message].
    count := count + 1].
window := LearnSqueakFormDemo new open.
model := window model.
input := window submorphs detect: [:m |
    (m isKindOf: PluggableTextMorph) and: [m getTextSelector = #nameText]].
slider := window submorphs detect: [:m | m isKindOf: SimpleSliderMorph].
[
input setText: 'Grace'; hasUnacceptedEdits: true.
check value: (model nameText = 'Ada') value: 'Buffer accepted too early'.
input accept.
check value: (model nameText = 'Grace') value: 'Accept failed'.
model toggleLoud; choice: 2; greet.
check value: (model result = 'WELCOME, GRACE.') value: 'Greeting failed'.
model greet.
check value: (model result = 'WELCOME, GRACE.') value: 'Repeat failed'.
slider setValue: 0.87.
check value: (model result = 'Slider value: 87') value: 'Slider callback failed'.
input setText: '   '; hasUnacceptedEdits: true; accept.
model greet.
check value: (model result = 'Please enter a name.') value: 'Blank validation failed'.
input setText: 'Unaccepted draft'; hasUnacceptedEdits: true.
model reset.
check value: (model nameText = 'Ada') value: 'Reset name failed'.
check value: (input text asString = 'Ada') value: 'Draft not discarded'.
check value: input hasUnacceptedEdits not value: 'Dirty editor after reset'.
check value: model loud not value: 'Reset checkbox failed'.
check value: (model choice = 1) value: 'Reset selection failed'.
check value: (slider getNumericValue rounded = 50) value: 'Reset slider failed'.
model greet.
check value: (model result = 'Hello, Ada.') value: 'Greeting after reset failed'.
model reset; reset.
check value: (model result = 'Change the controls, then click Greet.') value: 'Repeated reset failed'.
] ensure: [window delete].
count printString, ' form event checks passed'
Download complete stage .st

The test uses setText: plus an explicit dirty flag to prepare an editor buffer, then calls its real acceptance method. The GIF near the top records actual mouse and keyboard input instead.

03

Text input has an acceptance step

PluggableTextMorph connects an editor to a getter and setter. Its editor buffer can differ from the model until accepted. This form uses Enter to accept, so it behaves like a one-line input even though the underlying widget is a text editor.

Method excerpt · already included in the complete source
input := PluggableTextMorph on: self
    text: #nameText accept: #acceptName:.
input acceptOnCR: true; wrapFlag: false.
Method excerpt · already included in the complete source
acceptName: aText
    name := aText asString withBlanksTrimmed.
    self changed: #nameText.
    ^ true

The setter receives a Text, converts it to a String, trims surrounding blanks, and returns true to accept the edit. Returning false would reject it. changed: tells dependent views that the named value changed. The greeting action checks for an empty name and shows a helpful message instead of constructing a blank greeting.

The snippets in this and the next sections are excerpts from the installed methods, not independent Workspace programs. Their self means the form model. Browse LearnSqueakFormDemo to edit them.

04

Checkboxes and list selection

A checkbox asks for a Boolean state and sends an action when clicked. In this image the pluggable wrapper needs installButton to create its inner checkbox.

Method excerpt · already included in the complete source
check := PluggableCheckBoxMorph on: self
    getState: #loud action: #toggleLoud label: #loudLabel.
check installButton.
Method excerpt · already included in the complete source
toggleLoud
    loud := loud not.
    self changed: #loud

The label is supplied by the loudLabel getter. Keep state in the model rather than reading a drawn checkmark. For a list, provide its items, current selection, and a selection setter:

Method excerpt · already included in the complete source
list := PluggableListMorph on: self
    list: #choices selected: #choice changeSelected: #choice:.
Method excerpt · already included in the complete source
choice: anIndex
    choice := anIndex.
    self changed: #choice

Selections are one-based indices; zero means no selection. The model starts with index 1. Its greeting code uses at least 1 so clearing a selection falls back to Hello. The choices getter returns three strings. A list sends a new index; a checkbox sends a no-argument toggle action. Match each callback’s number of arguments to its selector.

05

Slider values and output updates

A slider maps its position onto a numeric range. The action selector ends in a colon because it receives one value. Drag the thin thumb, rather than dragging the window’s empty background.

Method excerpt · already included in the complete source
slider := SimpleSliderMorph new.
slider target: self; actionSelector: #level:;
    minVal: 0; maxVal: 100; adjustToValue: level.
Method excerpt · already included in the complete source
level: aNumber
    level := aNumber rounded.
    result := 'Slider value: ', level printString.
    self changed: #result
REAL SQUEAK CAPTURESCREENSHOT
A dragged native slider reports Slider value 87
The numeric callback was exercised by dragging the real slider.

adjustToValue: sets the initial thumb position in the 0–100 scale. setValue: uses the slider’s normalized 0–1 scale and invokes the target. Do not interchange the two. The output is another PluggableTextMorph bound to #result, with readOnly: true and no accept selector.

06

Containment, layout, and event flow

SystemWindow owns the controls. Each frame uses fractions of its content area: 0 is the left/top edge and 1 is the right/bottom edge. These relative rectangles keep controls arranged when the window changes size.

Method excerpt · already included in the complete source
window addMorph: input
    frame: (0.04@0.11 corner: 0.96@0.23).
window addMorph: button
    frame: (0.66@0.55 corner: 0.79@0.67).
window openInWorld; extent: 650@420; position: 300@150.

The event flow is click Greet → send greet to the model → update result → announce changed: #result → redraw output. The model does not need mouse coordinates. Use raw mouse events only when building a custom Morph; native buttons already handle press/release behavior.

Method excerpt · already included in the complete source
button := SimpleButtonMorph new
    label: 'Greet'; target: self; actionSelector: #greet; yourself.

Set the extent after opening: SystemWindow applies an initial size while opening. Avoid shrinking this example so far that labels become unusable. For production applications, consider ToolBuilder for more declarative layouts and keyboard navigation.

07

Test behavior without clicking

After setup, this independent model check answers 'WELCOME, GRACE.' with Print it. Testing model messages separately makes UI problems easier to isolate.

After setup · Workspace Print it
| model |
model := LearnSqueakFormDemo new.
model acceptName: 'Grace'; toggleLoud; choice: 2; greet.
model result
Download .st
REAL SQUEAK CAPTURESCREENSHOT
Form output reading WELCOME GRACE after accepted edits
A real window after text acceptance, checkbox toggle, list selection, and button action.

Common pitfalls: forgetting Enter leaves the previous accepted name; omitting the colon from #choice: gives the callback the wrong arity; mutating a model value without changed: can leave a stale view; evaluating these method excerpts in a Workspace gives self the wrong receiver.

Close the window with its red close control. Keep the tutorial class for practice, or remove only LearnSqueakFormDemo through the Browser when finished. Save an image to keep live state; export source to share code.

Build the calculator next

All setup and opener code ran in Squeak 6.1 build 23976. Widget contracts were checked in the image’s Browser. See official Squeak documentation and the development tools tutorial.