Bool Property

View Entity Bool Property Configuration Options

4. Bool Property

When you need to represent a simple yes/no, true/false, or on/off type of answer in your application, you should use a BoolProperty. This property type is perfect for things like checkboxes or toggle switches where there are only two possible options. It makes your forms more interactive and helps users quickly choose between two states.

For example, the IsNice property is defined using AddBoolProperty<bool>, which creates a checkbox in the UI. This property supports a special configuration method called TextRepresentation, which lets you define custom text labels for the true and false values. For instance, instead of showing just a checked or unchecked box, you can display "Yes" for true and "No" for false. This makes your UI easier to understand and more user-friendly, especially when the meaning of a checkbox isn't immediately obvious.

publicpartialclassEmployee:IBkEntity<Employee,ApplicationDbContext>

{

    publicvoidBkConfiguration(IBkEntityDesigner<Employee,ApplicationDbContext>designer)

    {

// Note: The AddBoolProperty method is generic, so you must specify the type (bool or bool?).// Note: Use bool? to allow the checkbox to be left unselected (nullable state).        designer.Properties.AddBoolProperty<bool>("IsNice",c=>

        {

// Sets the label text shown next to the checkbox.            c.Label("Is Nice");

// you can set how the value is represented in the UI            c.TextRepresentation("Yes","No");

// Adds a tooltip that appears when hovering over the checkbox.            c.ToolTip("Indicates if the person is considered nice");

// Applies a custom CSS class to the checkbox for styling purposes.            c.CssClass("is-nice-toggle");

// Hides the editor from the form by default.            c.HideEditor();

// Hides the column for this property in the grid view.            c.HideGridViewColumn();

// Sets the tab order for the editor when navigating with the Tab key.            c.TabIndex(4);

        });

    }

}

Configuration Options for AddBoolProperty<bool>

Method Description Parameters
Label Sets the label text that appears next to the checkbox or switch input. string label
TextRepresentation Sets the text for property value in the UI string trueText, string falseText
ToolTip Adds a tooltip that appears when hovering over the checkbox. string tooltip
CssClass Applies a custom CSS class to the boolean editor for styling purposes. string className
HideEditor Hides the checkbox or switch from the edit form by default. None
HideGridViewColumn Hides the column for this boolean property in the grid view. None
TabIndex Sets the tab order of the editor in the form when navigating with the Tab key. int tabIndex
ValidationRuleValue Adds a custom validation rule that uses the property value to determine validity. Func<bool, bool> rule,
string errorMessage,
string attributeName
ValidationRuleModel Applies a custom validation rule based on the entire model. Func<TModel, bool> rule,
string errorMessage,
string attributeName
ValidationRuleUsingDbContext Defines a custom validation rule that uses the database context and model data. Func<DbContext, TModel, bool> rule,
string errorMessage,
string attributeName
ValidationRuleUsingExistingAttribute Applies an existing .NET validation attribute to the boolean property. ValidationAttribute attribute
An unhandled error has occurred. Reload 🗙