So, if I wanted to have a <div contentEditable=true>{someModel.text}</div>
what’d be the most straightforward wat to do it without forking modapp-resource-component & modapp-base-component?
I totally missed this post when it was made. And I see you figured it out.
I will put this category on my watch-list, so I get notifications next time.
And I will still write a late reply, for anyone wondering similar things in the future
This answer goes for all components in modapp-resource-component
and modapp-base-component
:
// You can set the attributes on create
let txt = new ModelTxt(model, m => m.name, {
attributes: { contentEditable: 'true' }
});
// You can also set attributes after creation with setAttribute and removeAttribute
txt.setAttribute('contentEditable', 'false');
// But ModelTxt only supports the common case of changing text on model change.
// To update attributes on model change, you can wrap a Txt in a ModelComponent.
new ModelComponent(model, new Txt(), (m, c) => {
// Updating text string
c.setText(m.name);
// Updating an attribute
c.setAttribute('contentEditable', m.isEditable ? 'true' : 'false');
});