Saturday, February 23, 2008

Element.getAttribute

To tell Metawidget's Inspectors we don't want a label on a field, ideally we'd like to do...

@UiLabel( "" )

...or...

<property name="foo" label="">

Unfortunately, according to the DOM Element.getAttribute specification, it does not distinguish between 'an attribute having no value (eg. foo="")' and 'an attribute not existing'. In both cases getAttribute returns an empty String.

So to be able to specify an empty String without it just being ignored as a non-existant attribute, we need to put a String with a space...

@UiLabel( " " )

...or...

<property name="foo" label=" ">

...which is a bit sucky I know.

Suggested improvements welcome :)

Update: After playing around with label="null" for a bit, I noticed DOM supplies an Element.hasAttribute method for this purpose, so you can differentiate after all.

1 comments:

Mark Ashworth said...

Maybe

<property name="foo" label="NULL" />