Re: Textfield
Re: Textfield
- Subject: Re: Textfield
- From: John Stiles <email@hidden>
- Date: Sun, 2 Dec 2007 08:56:50 -0800
Long ago I had a Carbon app which did the five-text-fields thing to
enter serial numbers.
When I ported it to Cocoa, I changed it to automatically insert
hyphens in the text as the user typed.
This was actually a lot easier for several reasons:
- it looked more like the key displayed in email/on the CD case
- no need to handle quirky things like "if the user clicks in an
empty text field on the right and presses delete, where does the
insertion point go?"
- the user can use the arrow keys to move around freely in the text
field
- the user can click in the middle of a mostly-completed key, start
typing, and it will "do the right thing" (insert letters, reflowing
all the hyphens as appropriate)
Basically, any time the contents of the text field change, all you do
is:
- get the string and insertion point location
- for the next 3 steps, update the insertion point location any time
you add or remove characters in front of it:
- remove all the hyphens
- do any cleanup (capitalize, strip bad characters)
- reinsert the hyphens
- finally, replace the string and place the insertion point back into it
On Dec 2, 2007, at 7:29 AM, I. Savant wrote:
I have a window with 5 textfield to enter a serial number of 5x5
characters.
When I entrer 5 characters in a textfield, I want that the cursor
goes automatically in the next textfields.
Why not just use one text field and your own NSFormatter to keep
it formatted?
Otherwise, you can respond to each field's -textDidChange: ...
--
I.S.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
40blizzard.com
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden