Trigger nextkeyview based on NSTextField input length

  • Hello folks,

    I'm writing a license key input window. The license key is broken into four parts, separated by "-". I've created four NSTextFields for each component of the key to aid typing and identification (e.g. NSTextField1 - NSTextField2 - NSTextField3 - NSTextField4 ). The textfields utilize a NSFormatter subclass.

    What is the most appropriate way to trigger nextkeyview after x number of characters in the textfields? I'd like for the user to get forwarded to the next textfield after typing the appropriate number of characters in the current textfield. This is a common practice in license key windows.

    Should I put it [[inputField window ] selectNextKeyView:self] in the formatter subclass? Do it in the window controller?

    thanks for any thoughts,

    Jaime Magiera

    Sensory Research, Inc.
    http://www.sensoryresearch.net
  • On May 17, 2013, at 7:02 PM, Jaime Magiera <jaime...> wrote:

    > Hello folks,
    >
    > I'm writing a license key input window. The license key is broken into four parts, separated by "-". I've created four NSTextFields for each component of the key to aid typing and identification (e.g. NSTextField1 - NSTextField2 - NSTextField3 - NSTextField4 ). The textfields utilize a NSFormatter subclass.
    >
    > What is the most appropriate way to trigger nextkeyview after x number of characters in the textfields? I'd like for the user to get forwarded to the next textfield after typing the appropriate number of characters in the current textfield. This is a common practice in license key windows.
    >
    > Should I put it [[inputField window ] selectNextKeyView:self] in the formatter subclass? Do it in the window controller?

    The easiest approach following this design would be to sign the window controller up as the delegate for all the text fields and implement -controlTextDidChange: to make the next field first responder.

    But consider the following:

    - Replacing a character in the middle of a field shouldn't cause the cursor to advance to the next one just because the field has the right number of characters in it.

    - You have to implement special logic for copy and paste. (If you break pasting a license code into your license panel, your users will hate you.)

    - What happens when you delete all the characters in a field? Or position yourself at the front of a full field and hit Delete?

    So rather than the four-field approach, why not use _one_ text field with an NSFormatter subclass that adds and removes the dashes in the license code? Then you get all the text handling behavior users expect for free.

    --Kyle Sluder
  • On May 17, 2013, at 7:02 PM, Jaime Magiera wrote:

    > Hello folks,
    >
    > I'm writing a license key input window. The license key is broken into four parts, separated by "-". I've created four NSTextFields for each component of the key to aid typing and identification (e.g. NSTextField1 - NSTextField2 - NSTextField3 - NSTextField4 ). The textfields utilize a NSFormatter subclass.
    >
    > What is the most appropriate way to trigger nextkeyview after x number of characters in the textfields? I'd like for the user to get forwarded to the next textfield after typing the appropriate number of characters in the current textfield. This is a common practice in license key windows.
    >
    > Should I put it [[inputField window ] selectNextKeyView:self] in the formatter subclass? Do it in the window controller?
    >
    > thanks for any thoughts,

    Try this: http://cocoadev.com/wiki/MaskedTextField
  • On May 17, 2013, at 11:03 PM, Kyle Sluder <kyle...> wrote:

    > So rather than the four-field approach, why not use _one_ text field with an NSFormatter subclass that adds and removes the dashes in the license code? Then you get all the text handling behavior users expect for free.

    Very wise. Thanks Kyle.

    Jaime Magiera

    Sensory Research, Inc.
    http://www.sensoryresearch.net
previous month may 2013 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Go to today