I notice that you are removing the widget from it's parent. That doesn't
seem correct.

On Fri, Aug 12, 2011 at 12:55 PM, yourenzhuce <yourenzh...@gmail.com> wrote:

> I want to add a div on TextBox, when textbox's value is empty, the div
> will be show.
> It look good, but it can't receive the event. the EventHandler does
> not take effect.
>
> What's the problem??
>
> The code is:
> ----------------------------------------------------------------
>        public static HTML insertLabelUpon(final ValueBoxBase widget) {
>                final HTML label = new HTML();
>                label.setStyleName("PlugInLabel");
>
>                Element parent = widget.getElement().getParentElement();
>                if (parent == null) return null;
>                Element div = DOM.createDiv();
>                widget.removeFromParent();
>                parent.appendChild(div);
>                div.appendChild(widget.getElement());
>                div.appendChild(label.getElement());
>
>                div.getStyle().setProperty("position", "relative");
>                DOM.setStyleAttribute(label.getElement(), "position",
> "absolute");
>
>                label.addClickHandler(new ClickHandler() {
>                        @Override
>                        public void onClick(ClickEvent event) {
>                                widget.setFocus(true);
>                        }
>                });
>                widget.addFocusHandler(new FocusHandler() {
>                        @Override
>                        public void onFocus(FocusEvent event) {
>                                label.setVisible(false);
>                        }
>                });
>                widget.addBlurHandler(new BlurHandler() {
>                        @Override
>                        public void onBlur(BlurEvent event) {
>                                Object value = widget.getValue();
>                                if(value != null && value != "") {
>                                        label.setVisible(false);
>                                } else {
>                                        label.setVisible(true);
>                                }
>                        }
>                });
>
>                return label;
>        }
> ----------------------------------------------------------------
>
> the CSS:
> ----------------------------------------------------------------
> .PlugInLabel {
>        position: absolute;
>        font: 11px tahoma,arial,verdana,sans-serif !important;
>        left: 5px !important;
>        color: #999999;
> }
> ----------------------------------------------------------------
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To post to this group, send email to google-web-toolkit@googlegroups.com.
> To unsubscribe from this group, send email to
> google-web-toolkit+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to