Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    FYI: custom button in FormItem/click event bubbling

    Thought I'd share since I spent some time figuring this out and could not find it in the documentation.

    My objective was to have a FormItem that behaved like a button where the button text was dynamic based on the form value. I could not figure out how to get ButtonItem to do it. Instead the button text was the title of the form item. If it is possible, it might be nice if the documentation were enhanced to indicate how.

    Instead, I used a StaticTextItem:

    Code:
            item.setValueFormatter(new FormItemValueFormatter()
            {
                @Override
                public String formatValue(Object value, Record record, DynamicForm form, FormItem item)
                {
                    final String v = null == value ? "--" : value.toString();
                    return "<button [B]handleNativeEvents=false[/B]>" + v + "</button>";
                }
            });
            item.addClickHandler(new ClickHandler()
            {
                @Override
                public void onClick(ClickEvent event)
                {
                    // whatever
                }
            });
    The magic is the handleNativeEvents=false attribute on the button html. SmartGWT won't process clicks on child elements without it.

    Hopefully this saves someone some time. Standard disclaimer about using undocumented features, yada yada...
Working...
X