[haiku-development] RFC: B_INVALID flag for BControlLook

  • From: pulkomandy <pulkomandy@xxxxxxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Wed, 1 Oct 2014 09:34:50 +0200

Hi,

I'm implementing a date and time picker for WebKit (to be used with
HTML5 date and time input types). I use a BTextControl to let the user
enter the year, which is not bounded. Other values (month, hour,
minutes) are implemented as BMenuFields.

At first I thought of filtering input to my text field to allow only
digits. This is rather difficult to implement, as we only have support
for excluding characters from the allowed input range of a BTextView.
Moreover, I now think this is a bad idea, because it leads to rejecting
user input without any feedback, and will look like the field is not
accepting input at all.

I think a better solution would be to allow any text to be typed in the
field, but disable the "Done" button to close the window as long as the
value is invalid. To make the problem obvious to the user, the text
control should get a B_FAILURE_COLOR (red) border.

I can implement this by subclassing BTextControl and overriding the Draw
method. However, I think this could be used in other places and a
generic solution would be better.


I would introduce a B_INVALID flag in BControlLook (alongside B_FOCUSED,
B_CLICKED, etc.). The flag would trigger using the B_FAILURE_COLOR for
the border as described above. It will be used mainly on BTextControl,
which is the only control accepting freeform input from the keyboard.

Does that sound like a good way to handle the problem? Or do you have
better recommandations on this?

Thanks,
-- 
Adrien.

Other related posts: