From VisualWorks®, Release 5i.1 Beta of October 8, 1999 on October 28, 1999 at 11:13:22 am (Dialog confirm: 'You are filing-in a Parcel source file!\\While this is possible it will not have\the same effect as loading the parcel.\None of the Parcel''s prerequisites will\be loaded and none of its load actions\will be performed.\\Are you sure you want to file-in?' withCRs) ifFalse: [self error: 'Parcel file-in abandoned. Choose terminate or close.'] <class> <name>FieldValidInputExample</name> <environment>Examples</environment> <super>UI.ApplicationModel</super> <private>false</private> none username accessCode <imports></imports> <category>Examples-Help</category> </class> <comment> Examples.FieldValidInputExample
This example class demonstrates a technique for validating input to a field when the user accepts the input.
</comment> <methods> Examples.FieldValidInputExample <category>initialize-release</category>
initialize super initialize. username := 'guest' asValue. accessCode := 0 asValue.
</methods> <methods> Examples.FieldValidInputExample <category>aspects</category>
accessCode ^accessCode
username ^username
</methods> <methods> Examples.FieldValidInputExample <category>validation messages</category>
validateAccessCode: aController "Check whether the user entered a number. If not, warn the user. If so, check whether the number is in the right range. If not, warn the user." | entry lowerLimit upperLimit | lowerLimit := 50. upperLimit := 100. "Test whether the input can be converted to a number. If not, warn the user (and reject the input). If so, get the number." aController hasEditValue ifTrue: [ entry := aController editValue.] ifFalse: [Dialog warn: 'Enter a number.'. ^false]. "If the access code is in the wrong range, warn the user (and reject the input)." ^(lowerLimit < entry) & (entry < upperLimit) ifTrue: [true] ifFalse: [Dialog warn: 'Enter a number between ', lowerLimit printString , ' and ', upperLimit printString, '.'. false]
validateUsername: aController "Check the length of the entered username. Warn the user if the entered input is too long." | entry lengthLimit | lengthLimit := 6. entry := aController editValue. "If the username is too long, warn the user (and reject the input)." ^entry size <= lengthLimit ifTrue: [true] ifFalse: [Dialog warn: 'Please enter only ', lengthLimit printString, ' characters.'. false]
</methods> <methods> Examples.FieldValidInputExample class <category>interface specs</category>
windowSpec "UIPainter new openOnClass: self andSelector: #windowSpec" <resource: #canvas> ^#(#FullSpec #window: #(#WindowSpec #label: 'FieldValidInputExample' #min: #(#Point 40 20 ) #bounds: #(#Rectangle 701 521 961 705 ) ) #component: #(#SpecCollection #collection: #( #(#InputFieldSpec #layout: #(#Rectangle 54 43 203 73 ) #model: #username #callbacksSpec: #(#UIEventCallbackSubSpec #requestFocusOutSelector: #validateUsername: #requestValueChangeSelector: #validateUsername: ) #type: #string ) #(#LabelSpec #layout: #(#Point 54 13 ) #label: 'Username:' ) #(#InputFieldSpec #layout: #(#Rectangle 54 119 203 149 ) #model: #accessCode #callbacksSpec: #(#UIEventCallbackSubSpec #requestFocusOutSelector: #validateAccessCode: #requestValueChangeSelector: #validateAccessCode: ) #type: #number ) #(#LabelSpec #layout: #(#Point 54 89 ) #label: 'Access Code:' ) ) ) )
</methods> "Imported Classes:" self error: 'Attempting to file-in parcel imports. Choose terminate or close' <class> <name>ApplicationModel</name> <environment>UI</environment> <super>UI.Model</super> <private>false</private> none builder uiSession <imports></imports> <category>UIBuilder-Framework</category> </class>