0

get selected text from Textbox

asked 2009-03-09 13:46:17 +0800

HananW gravatar image HananW
160 2

Hi All,
Consider the following situation:
I have a Textbox for defining item's description and a search button to allow the user searching for items with similar description (so far it is like a bandbox). I want to allow the user to select part of the text and when the search button is pressed do the search according to the selected text (if no text selected then search using the Textbox value).

Here is the problem:
1. Textbox does not have a getSelectedtext method.
2. If I use the "OnSelection" event to store the selected text I have a different problem (there is no clear selection event, at least I did not see any).

This cause problem in the following scenario:
1. Select some text (the "onSelection" event store the selected text.
2. Select a different component.
3. Use the mouse to re-select the description Textbox (The selection is cleared and no event fired so the stored selection text has value, but there is actually no selection).

Please advise,
Hanan.

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2009-03-10 19:24:51 +0800

james gravatar image james
255 2

updated 2009-03-10 19:26:55 +0800

http://docs.zkoss.org/wiki/Component_Events
look for "onSelection" (roughly 1/3 down the page)

Using the getStart and getEnd methods it mentions, you can parse what is currently in the textbox, and retrieve the selected text.
Hopefully that at least helps some.
And to be honest, I've never used it... so I don't know how well it will work for what you want...

link publish delete flag offensive edit

answered 2009-03-10 21:09:25 +0800

HananW gravatar image HananW
160 2

Hi James,

Thanks for your answer, but as I said, I tried using it and there is a problem since there is no event when the selection is cleared. In that case the user does not see any selection, but I have the previous selection save and this is what I am using (if there was a clear event then I could use it to mar that there is no selection).

Regards,
Hanan.

link publish delete flag offensive edit

answered 2011-05-06 12:48:12 +0800

frik gravatar image frik
84 1

Any progress on this issue? I see similar issues throughout Zk. For example you don't know when a listbox selection goes away (many reasons this could happen)

link publish delete flag offensive edit

answered 2011-05-27 01:23:56 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

@HananW,

The browser seems not to fire an event when user clear the selection.

@Frik,

You issue looks like another question, not for the text selection.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-03-09 13:46:17 +0800

Seen: 716 times

Last updated: May 27 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More