Reputation: 1432
I'm trying to create a custom widget in GWT that creates a div with contenteditable=true inside of it. The problem is that when I create this div and I initialize this widget, the div does not have the contenteditable property.
my code:
public MyWidget(){
FlowPanel panel = new FlowPanel();
initWidget(panel);
HTML div = new HTML("<div id=\"my-div\" contenteditable=true></div>");
div.setText("hello there");
div.addHandler(new MyWidgetKeyDownHandler(), KeyDownEvent.getType());
mDiv = div;
panel.add(div);
}
But when I run the code and I inspect the source, I see this:
<div>
<div class="gwt-HTML">hello there</div>
</div>
So it looks like it's missing the contenteditable tag as well as the id. What am I doing wrong here? How can I create this contenteditable div widget?
Upvotes: 2
Views: 1769
Reputation: 20890
div.getElement().setAttribute('contenteditable', 'true');
I would work around your requirement for a specific id. You can set one with ensureDebugId but you might find it simpler to do without it.
Upvotes: 3