Multiline CPTextField

140 views
Skip to first unread message

RCLConcepts

unread,
Jul 18, 2009, 1:07:26 AM7/18/09
to Cappuccino & Objective-J
Unless I'm missing something there is currently no good way to add a
mulitline editable textfield into your application. From what I've
gathered the dom element for the textfield is an input element. A
multiline textfield should use a text area.

What is the best way to work around this?

What if we replaced line 216 of CPTextField.j

CPTextFieldDOMInputElement = document.createElement("input");

with a conditional statement saying basically if the textfield is
larger than a single line of text use

CPTextFieldDOMInputElement = document.createElement("textarea");

instead?

Saikat Chakrabarti

unread,
Jul 18, 2009, 3:55:03 AM7/18/09
to objec...@googlegroups.com
I have been using the code at http://gist.github.com/raw/9848/51a8df264ec328b17adc2d7aa826058e256f67d0 for now, but agreed that there should be a real solution for this.

millenomi

unread,
Jul 18, 2009, 5:37:25 AM7/18/09
to objec...@googlegroups.com
On Sat, Jul 18, 2009 at 7:07 AM, RCLConcepts<rclco...@gmail.com> wrote:
>
> Unless I'm missing something there is currently no good way to add a
> mulitline editable textfield into your application. From what I've
> gathered the dom element for the textfield is an input element. A
> multiline textfield should use a text area.

Note that in Cocoa there are two classes (NSTextField and NSTextView)
that are monoline/no rich text and multiline/possibly rich text
respectively. Maybe Cappuccino devs will respect the division. — ∞

RCLConcepts

unread,
Jul 18, 2009, 12:50:15 PM7/18/09
to Cappuccino & Objective-J
So I'm not actually for a multiline CPTextField but instead a
CPTextView?
Honestly, that's not really a problem I just think it would just be
nice to have multiline textfield support.

Thank you Saikat for that... I'll take a look. :)

On Jul 18, 4:37 am, millenomi <millen...@gmail.com> wrote:

RCLConcepts

unread,
Jul 18, 2009, 1:21:33 PM7/18/09
to Cappuccino & Objective-J
I do have a question though. How is interface builder handling the
textfield? I drag out a control with the class NSTextField and if I
save it and look at the XML of the nib it still shows an NSTextField.

On Jul 18, 4:37 am, millenomi <millen...@gmail.com> wrote:

Francisco Tolmasky

unread,
Jul 19, 2009, 10:33:05 PM7/19/09
to Cappuccino & Objective-J
From the docs on NSTextFieldCell/NSCell it seems to be a combination
of a number of settings including "setWraps:"

RCLConcepts

unread,
Jul 20, 2009, 1:51:19 AM7/20/09
to Cappuccino & Objective-J
So for the time being would could simply add a method called setWraps
which would replace the input dom element with a textarea dom
element.

This what I came up with...
http://gist.github.com/150179

Nothing fancy, just a getter and setter for a _wraps ivar with a
conditional for the dom element.
I haven't tested it yet, but I need to get to bed.

RCLConcepts

unread,
Jul 21, 2009, 8:02:33 PM7/21/09
to Cappuccino & Objective-J
I would like to follow up. With the last commit on the master branch I
made some applied the same "patch"

http://gist.github.com/150179

now hosts the new version of CPTextField.j which contains the ability
to call setWraps:YES which will use a textarea instead of a input. You
should also probably call setLineBreakMode:CPLineBreakByWordWrapping
on the textField too otherwise your wraps wont stay there after the
field loses focus.

There is currently no support for manual line breaks (the return key)
but this is a start. :)

Enjoy!

-Randy

RCLConcepts

unread,
Jul 21, 2009, 8:08:32 PM7/21/09
to Cappuccino & Objective-J
That first sentence doesn't make a lot of sense. Sorry about that.
What I meant to say is since the last commit to the master branch made
changes to the CPTextField I reapplied this "textarea" patch.

I also added some things to it preventing resizing and preventing the
scroll bar from showing up on an overflow.

brainysmurf

unread,
Jul 23, 2009, 1:54:43 AM7/23/09
to Cappuccino & Objective-J
Is there a way to get whatever text is currently selected by the user,
programatically?

Saikat Chakrabarti

unread,
Jul 28, 2009, 1:56:20 PM7/28/09
to objec...@googlegroups.com
Hi Randall,

I just tried out your patch, and I like the idea, but I don't think it's enough to really get multiline text support working.  One problem I am having right now with it is that CPTextField hardcodes the return key to mean text is done being inputted (and it's done in a way that isn't easy to override in a subclass).  This makes it impossible to actually add new lines in a multiline input by hitting enter.  Did you have a way for getting around this?  I've been getting around it by changing the CPTextFieldKeyDownFunction to send a message to a delegate when return is pressed.

Saikat Chakrabarti

unread,
Jul 28, 2009, 1:57:55 PM7/28/09
to objec...@googlegroups.com
I just realized that wasn't very clear - I had been getting around the hardcoded return handling by sending a message to a delegate in another case where I needed to specially handle the return key.  

RCLConcepts

unread,
Jul 28, 2009, 5:23:55 PM7/28/09
to Cappuccino & Objective-J
I've added more changes to CPTextField in my fork of Cappuccino.
http://github.com/Me1000/cappuccino/tree/master
I rewrote support for multiline support so that it is implemented a
little cleaner (modeled after the secure text field implementation)

I also fixed a bug in the secure text field in the event manager.

The default behavior for the enter key in any NSTextField in Cocoa is
to select the text. I've made those changes to all textfields too. I
know that's not what you want, but that's how cocoa handle it. But
since you're replacing the CPTextField.j file anyway you might
consider looking at the event handlers in the file and changing them
accordingly.

Feel free to make fixes. For some reason when you hit enter now, it
only actually selects the text of the first CPTextField that gets
focus. I'm not sure what I'm going to do with it yet though. I really
wish we could get this multiline support in the 280north master
branch. Until then, this what we've got to work with. :/

On Jul 28, 12:57 pm, Saikat Chakrabarti <saik...@gmail.com> wrote:
> I just realized that wasn't very clear - I had been getting around the
> hardcoded return handling by sending a message to a delegate in another case
> where I needed to specially handle the return key.
>
> On Tue, Jul 28, 2009 at 10:56 AM, Saikat Chakrabarti <saik...@gmail.com>wrote:
>
>
>
> > Hi Randall,
> > I just tried out your patch, and I like the idea, but I don't think it's
> > enough to really get multiline text support working.  One problem I am
> > having right now with it is that CPTextField hardcodes the return key to
> > mean text is done being inputted (and it's done in a way that isn't easy to
> > override in a
> > subclass).  This makes it impossible to actually add new lines in a multiline input by hitting enter.  Did you have a way for getting around this?  I've been getting around it by changing
> > the CPTextFieldKeyDownFunction to send a message to a delegate when return
> > is pressed.
>
Reply all
Reply to author
Forward
0 new messages