2 votes

Emptiness

Nullable Property Value Converters for value types in Umbraco.

Why would I want that?

If an editor hasn't set a value for a "value type" property, then these converters will return null instead of a default value. This makes editor intent clearer - you can tell the difference between an integer that an edtor intentionally chose to be "0" as opposed to an integer property that's been left empty.

The Converters

Nullable Property Value Converters

Return null if an editor has not entered a value.

Enabled by default:
  • NullableDatePickerConverter
  • NullableDecimalConverter
  • NullableIntegerConverter
Disabled by default:
  • NullableLabelConverter

Property Value Converters for Toggles (True/False)

Though they don't have a null state in the UI, they can be empty if:

  1. A property has been added to a content type, but some content of that type has not been (re)published since.
  2. Content has been created via the API, without the property value having been set.

In these cases the following converters might be helpful...

YesNoDefaultConverter

Enabled by default. This converter returns the "Initial State" (default) value that has been configured in the property editor's settings.

NullableYesNoConverter

Disabled by default.

Configuration

You can configure Emptiness with appsettings.json like this:

  "Emptiness": {
    "EnabledConverters": [
      "NullableDatePickerConverter",
      "NullableDecimalConverter",
      "NullableIntegerConverter"
    ],
    "TrueFalseConverter": "Nullable"
  }

This is the default configuration.

EnabledConverters

If provided, enables only the PVCs listed.

Property Value Converter names:

  • NullableDatePickerConverter
  • NullableDecimalConverter
  • NullableIntegerConverter
  • NullableLabelConverter

 

TrueFalseConverter

Determines the True/False (Yes/No) conveter to use for booleans.

Options:

  • Core - use Umbraco's built in converter.
  • DefaultValue - use the YesNoDefaultConverter
  • Nullable - use the NullableYesNoConverter

License(s) & Copyright

Copyright © 2022 Jason Elkin

Licensed under the MIT License.

Crate image created by vectorpocket - www.freepik.com

Screenshots

NuGet install instructions for Umbraco 9+

dotnet add package Our.Umbraco.Emptiness

Package owner

Jason Elkin

Jason Elkin

Jason has 348 karma points

Package Compatibility

This package is compatible with the following versions as reported by community members who have downloaded this package:
Untested or doesn't work on Umbraco Cloud
Version 11.0.x (untested)
Version 10.3.x (untested)
Version 10.2.x (untested)
Version 10.1.x (untested)
Version 10.0.x (100%)
Version 9.5.x (100%)
Version 9.4.x (100%)
Version 9.3.x (100%)
Version 9.2.x (untested)
Version 9.1.x (untested)
Version 9.0.x (untested)
Version 8.18.x (untested)

You must login before you can report on package compatibility.

Previously reported to work on versions:

Package Information

  • Package owner: Jason Elkin
  • Created: 01/04/2022
  • Current version 2.0.0
  • License MIT
  • Downloads on Our: 0
  • Downloads on NuGet: 319
  • Total downloads : 319