To enhance the data model, medini offers various types like string or date or custom scripted properties. On the user interface they are rendered nicely, but sometimes a script has to deal with those properties and its required to test for an existence of a value before the script can move on, this article quickly tackles what need to be considered.
Single String Property
If you have a single string value, its rather simple, you either get a string or you get "undefined" or "null". So to distinguish you simply can do:
if (self.user_single_property != undefined) {
// TODO do something with the value
}
// be careful, this works as well
if (self.user_single_property) {
// TODO do something with the value
}
// but is the same as
if (self.user_single_property != undefined && self.user_single_property != "") {
// TODO do something with the value
} Multi-String Property
These values are always returned as a list. You can use isEmpty() on the list or size() == 0 to check if there is nothing set:
if (!self.user_multi_value.isEmpty()) {
console.log("There are {0} values inside", self.user_multi_value.size());
// TODO do something with the values in the list
}