I’ve implemented some attributes as enums, and, unlike simpler types (numbers, for instance), they do not seem to behave as documented.
TextDraw.attributes.add('VerticalAnchor', {
type: 'string',
enum: [
{ 'Centre' : "Centre" },
{ 'Top' : "Top" },
{ 'Bottom' : "Bottom" }
],
default: 'Centre',
description: 'Select the style of vertical anchoring for this text item'
});
Specifically, if I set no default, the value of the attribute is always ‘null’. If I set a default, the value is always the default, and never reflects changes made in the editor. Lastly, the function that should be called when an attribute changes never fires, ie:
// fires for all attribute changes
this.on('attr', function(name, value, prev) {
// new attribute value
console.log("Attribute change: " + name + " => " + value + " prev: " + prev );
});
(this fires for numeric attribute changes)
… am I doing something wrong? I’d dearly like to use an enum for readability. Thanks lots!
Pretty weird, I forked your example, of course it does indeed work!
Then I took that code and put it into my JS file, no joy… then I created an identical test.js to yours in my own project, and that code worked just fine. Also, my own code fragment works fine in your test project.
I noticed that if I clicked away from the object and back again, the settings hadn’t ‘stuck’ and reset to ‘…’, so eventually, I actually reloaded the editor page and boom… things started working. Pretty confused, but everything is AOK now.