nstextfield question

  • Hi,

    I might be getting sleepy and overlooking the obvious, but I have a panel with a few text fields and I'm trying to figure out what gets called after entering a value into a text field and while it's still highlighted clicking it again?  In my case when entering a value into one of my text fields (let's say "30") I append a string to that value (let's say "Days").  I do this in the action method.  In my subclass in mouseDown I make it where if the value is "30 Days" when clicking the text field I will remove the "Days" so the user can easily edit only the "30" and I append the "Days" once again in the action method.  My problem is after clicking Enter for that text field if the user would try to edit it again without that text field ever losing focus the "Days" is not removed because mouseDown doesn't get called.  And I haven't been able to figure out what does get called in this situation?  Thanks,

    rc
  • You should have a look at the documentation for NSFormatter. You can define a formatter for your text field that gets called when a number of different things happen to/in the text field.

    You might also want to have a look at the delegate methods available for an NSTextField which get called when other things happen to/in the field.

    At first you might think that building a formatter for a field that already does what you want is redundant but you may find that the advantage of being able to get control at virtually all stages of editing is worth it. I certainly do.

    On Apr 27, 2012, at 12:12 PM, Rick C. wrote:

    > Hi,
    >
    > I might be getting sleepy and overlooking the obvious, but I have a panel with a few text fields and I'm trying to figure out what gets called after entering a value into a text field and while it's still highlighted clicking it again?  In my case when entering a value into one of my text fields (let's say "30") I append a string to that value (let's say "Days").  I do this in the action method.  In my subclass in mouseDown I make it where if the value is "30 Days" when clicking the text field I will remove the "Days" so the user can easily edit only the "30" and I append the "Days" once again in the action method.  My problem is after clicking Enter for that text field if the user would try to edit it again without that text field ever losing focus the "Days" is not removed because mouseDown doesn't get called.  And I haven't been able to figure out what does get called in this situation?  Thanks,
    >
    > rc

    Charlie Dickman
    <3tothe4th...>
  • Thanks for the reply but unfortunately I'm still stuck.  Yes I did try the delegate methods before posting here.  I did not try the formatter methods but can't figure out a way to make it work either.  None of these methods seem to get called if the text field is still in focus and the value is still highlighted.  Now if I would tab to another text field it's no problem because mouseDown will get called again.  But with only clicking Enter and immediately trying to edit again by clicking with the mouse (while the value is still highlighted) nothing seems to get called.  What am I missing here?  Thanks,

    rc

    On Apr 28, 2012, at 12:34 AM, Charlie Dickman wrote:

    > You should have a look at the documentation for NSFormatter. You can define a formatter for your text field that gets called when a number of different things happen to/in the text field.
    >
    > You might also want to have a look at the delegate methods available for an NSTextField which get called when other things happen to/in the field.
    >
    > At first you might think that building a formatter for a field that already does what you want is redundant but you may find that the advantage of being able to get control at virtually all stages of editing is worth it. I certainly do.
    >
    > On Apr 27, 2012, at 12:12 PM, Rick C. wrote:
    >
    >> Hi,
    >>
    >> I might be getting sleepy and overlooking the obvious, but I have a panel with a few text fields and I'm trying to figure out what gets called after entering a value into a text field and while it's still highlighted clicking it again?  In my case when entering a value into one of my text fields (let's say "30") I append a string to that value (let's say "Days").  I do this in the action method.  In my subclass in mouseDown I make it where if the value is "30 Days" when clicking the text field I will remove the "Days" so the user can easily edit only the "30" and I append the "Days" once again in the action method.  My problem is after clicking Enter for that text field if the user would try to edit it again without that text field ever losing focus the "Days" is not removed because mouseDown doesn't get called.  And I haven't been able to figure out what does get called in this situation?  Thanks,
    >>
    >> rc
    >
    > Charlie Dickman
    > <3tothe4th...>
    >
    >
    >
  • Use NSNumberFormatter as correctly suggested. You can set its -positiveSuffix: string to "Days" and that's it. You're done.

    --Graham

    On 28/04/2012, at 2:41 PM, Rick C. wrote:

    > Thanks for the reply but unfortunately I'm still stuck.  Yes I did try the delegate methods before posting here.  I did not try the formatter methods but can't figure out a way to make it work either.  None of these methods seem to get called if the text field is still in focus and the value is still highlighted.  Now if I would tab to another text field it's no problem because mouseDown will get called again.  But with only clicking Enter and immediately trying to edit again by clicking with the mouse (while the value is still highlighted) nothing seems to get called.  What am I missing here?  Thanks,
    >
    > rc
    >
    >
    >
    > On Apr 28, 2012, at 12:34 AM, Charlie Dickman wrote:
    >
    >> You should have a look at the documentation for NSFormatter. You can define a formatter for your text field that gets called when a number of different things happen to/in the text field.
    >>
    >> You might also want to have a look at the delegate methods available for an NSTextField which get called when other things happen to/in the field.
    >>
    >> At first you might think that building a formatter for a field that already does what you want is redundant but you may find that the advantage of being able to get control at virtually all stages of editing is worth it. I certainly do.
    >>
    >> On Apr 27, 2012, at 12:12 PM, Rick C. wrote:
    >>
    >>> Hi,
    >>>
    >>> I might be getting sleepy and overlooking the obvious, but I have a panel with a few text fields and I'm trying to figure out what gets called after entering a value into a text field and while it's still highlighted clicking it again?  In my case when entering a value into one of my text fields (let's say "30") I append a string to that value (let's say "Days").  I do this in the action method.  In my subclass in mouseDown I make it where if the value is "30 Days" when clicking the text field I will remove the "Days" so the user can easily edit only the "30" and I append the "Days" once again in the action method.  My problem is after clicking Enter for that text field if the user would try to edit it again without that text field ever losing focus the "Days" is not removed because mouseDown doesn't get called.  And I haven't been able to figure out what does get called in this situation?  Thanks,
  • I think I got it working thanks for the help!

    On Apr 28, 2012, at 1:48 PM, Graham Cox wrote:

    > Use NSNumberFormatter as correctly suggested. You can set its -positiveSuffix: string to "Days" and that's it. You're done.
    >
    > --Graham
    >
    >
    >
    >
    >
    > On 28/04/2012, at 2:41 PM, Rick C. wrote:
    >
    >> Thanks for the reply but unfortunately I'm still stuck.  Yes I did try the delegate methods before posting here.  I did not try the formatter methods but can't figure out a way to make it work either.  None of these methods seem to get called if the text field is still in focus and the value is still highlighted.  Now if I would tab to another text field it's no problem because mouseDown will get called again.  But with only clicking Enter and immediately trying to edit again by clicking with the mouse (while the value is still highlighted) nothing seems to get called.  What am I missing here?  Thanks,
    >>
    >> rc
    >>
    >>
    >>
    >> On Apr 28, 2012, at 12:34 AM, Charlie Dickman wrote:
    >>
    >>> You should have a look at the documentation for NSFormatter. You can define a formatter for your text field that gets called when a number of different things happen to/in the text field.
    >>>
    >>> You might also want to have a look at the delegate methods available for an NSTextField which get called when other things happen to/in the field.
    >>>
    >>> At first you might think that building a formatter for a field that already does what you want is redundant but you may find that the advantage of being able to get control at virtually all stages of editing is worth it. I certainly do.
    >>>
    >>> On Apr 27, 2012, at 12:12 PM, Rick C. wrote:
    >>>
    >>>> Hi,
    >>>>
    >>>> I might be getting sleepy and overlooking the obvious, but I have a panel with a few text fields and I'm trying to figure out what gets called after entering a value into a text field and while it's still highlighted clicking it again?  In my case when entering a value into one of my text fields (let's say "30") I append a string to that value (let's say "Days").  I do this in the action method.  In my subclass in mouseDown I make it where if the value is "30 Days" when clicking the text field I will remove the "Days" so the user can easily edit only the "30" and I append the "Days" once again in the action method.  My problem is after clicking Enter for that text field if the user would try to edit it again without that text field ever losing focus the "Days" is not removed because mouseDown doesn't get called.  And I haven't been able to figure out what does get called in this situation?  Thanks,
    >
previous month april 2012 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            
Go to today