Widget XML integer type must be required?

4
Hi, I'm interfacing with my own widget, and i'd like to pass an integer property like: property key="nr" type="integer" defaultValue="" required="false" however the Modeler 2.5.0.1 complains: Error in property 'nr': Property must specify a default value. Error in property 'nr': Property must be required. This should not be the case according to the specification: https://world.mendix.com/pages/releaseview.action?pageId=11439304 Interestingly, if i change the type="integer" to type="string" it does work correctly. So, i can use that as a workaround. But, is this a small bug? or am i doing something wrong? Thanks! Jan
asked
4 answers
4

An integer is never allowed to be empty. So the combination of not required and an empty default value is invalid. I suggest using the default value 0, and remove the required attribute (which is not applicable for integers), or if you really want to support the value '', use a String, or use default '-1'.

(minus one might sound awkward as default value, but it is a quite common approach to use -1 as a 'no value' value. For example search functions return -1 as index if nothing found, and -1 as tabindex means that an element should not be accessible by keyboard.)

answered
3

Probebly the specification is wrong, Mendix does not like it when you initialize an empty or null value thus it seems logical that they would not allow you to initialize an empty integer as there is no such thing.

Try setting it to 0 and then try again. I am not sure why it is complaining about your required tag but it might be doing that because of the syntax error at the defaultValue.

answered
2

Thanks for the quick answers guys!

I can of course parse the string myself in javascript. However, the point is to have the modeler already check the type before deployment. In that way an error will be caught faster. (which, i assume, is one of the ideas behind requiring these types in the XML)

To set a default value of -1 or 0 is not really acceptable when e.g. passing a minimum value for an axis. Cause these values will then be treated as the minimum. The only option would be null or NaN which i think you could arguably see as a valid Integer type.

About the XML specifications: if you look at Boolean, there it explicitly says "Required attributes: defaultValue". No such requirements are there for Integer.

I will use the string type, and deal with wrong (textual) input in the javascript widget. I'd prefer a check in the Modeler, but no big deal :).

Thanks!

Jan

answered
1

The specificiation is not wrong, but it does seem incomplete ;] To create a check in the moddeler you could add a boolean that checks if your standard value (0 for example) is default or an actual value.

I still do not truly understand with what is wrong with initilizing it with it's default value. Unless it is a general widget that can be applied in multiple situations and thus can have different default values in different situations. But even then i would still initialize it at 0 or -1 as Michel suggested

answered