Model Object
propertyIsBlank()
Signature
Section titled “Signature”propertyIsBlank() — returns boolean
Available in: model
Category: Miscellaneous Functions
Description
Section titled “Description”Returns true if the specified property doesn’t exist on the model or is an empty string.
This method is the inverse of propertyIsPresent().
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
property | string | yes | — | Name of property to inspect. |
Examples
Section titled “Examples”// 1. Check if a property is blank before sending a notification
user = model("User").findByKey(params.userId);
if (user.propertyIsBlank("email")) {
flashInsert(error="Please provide an email address before continuing.");
}
// 2. Conditionally set a default value when a property is blank
product = model("Product").findByKey(params.id);
if (product.propertyIsBlank("description")) {
product.description = "No description available.";
product.save();
}
// 3. Use propertyIsBlank alongside its inverse propertyIsPresent for branching logic
post = model("Post").findByKey(params.postId);
if (post.propertyIsBlank("publishedAt")) {
// post has never been published
writeOutput("Draft");
} else {
// propertyIsPresent("publishedAt") would return true here
writeOutput("Published on #post.publishedAt#");
}