How to respond to focus changes on ComposableModel? (Spec)

138 Views Asked by At

I'm trying to create a DateInputFieldModel (subclass of ComposableModel).

It uses a TextInputFieldModel as inputField.
I set inputField autoAccept: true..

I don't want to use return/enter to accept.

While typing, I'm checking with acceptBlock whether the input text is interpretable as a date.
In my case, for instance one digit is already interpretable as a date.
When you type 5, this would mean the 5th of the current month of the current year.

When the input field loses focus (tab or mouse), I'd like to render the final representation of the date into the inputField, and update the date value of my DateInputFieldModel.

Any pointers on how to achieve this?

2

There are 2 best solutions below

1
On

The underlying Morph gets send #keyboardFocusChange:

You probably need to add #whenFocusChanged: somewhere in the ComposableModel hierarchy and make sure it is called from the correct AbstractMorphicAdapter subclasses

0
On

In response to Stephan Eggermont's suggestion I altered following method

MorphicTextInputFieldAdapter>>adapt: aModel
  super adapt: aModel.
  aModel
    whenBuiltDo: [ :w | 
      w widget color: Smalltalk ui theme backgroundColor.
      w widget widget textMorph 
         onAnnouncement: MorphGotFocus, MorphLostFocus  
         send: #announce: to: aModel ]

This works but the drilldown w widget widget textMorph is a bit awkward.

In my DateInputFieldModel I subscribed to the announcements

inputField on: MorphLostFocus send: #lostFocus to: self.