Using integer as data source for checkbox

In the database (table "project") I only have an integer attribute ("Inactive"). How can I use this attribute as a data source for my checkbox and also convert and write it back as an integer?
Inactive_attribute

Currently I use this for my value property: ${project.Inactive == 1} what shows the correct value.

But I get an error inside the CheckBox component, saying: "The type or namespace name 'EditProjectComponent' could not be found (are you missing a using directive or an assembly revernece?)

According to Data binding with a string value using a Checkbox - Radzen IDE (Blazor server-side) - Radzen I understand that the checkbox component needs a boolean.

  1. So I guess I have to implement a conversion on the change event to get the "Checked" parameter of the checkbox back into the database. What type do I need (Invoke data source method? and what are the parameters.
  2. Do I need to do this over a custom poperty on my page or can I change the project.Inactive variable of the model?

The best option is to add additional boolean property to your model and use it for the CheckBox. You can check something similar here:

1 Like

Thank you for the quick response about the link about how to extend my model. I read it carefully. The concept will come in handy one time, for sure. I will consider that way, when I need additional business logic to create a boolean out of a more complex value (my integer is only just 0 or 1 or NULL).

I found a way that works on the "UI" side, please let me know, if you consider this bad practice.

  1. I checked the json file first:
                                {
                                  "name": "projectInactiveCheckbox",
                                  "type": "checkbox",
                                  "value": "${project.Inactive == 1}",
                                  "valueType": "Cora.Pages.EditProjectComponent"
                                }

The valueType made me worring, so I changed it to bool

                                {
                                  "name": "projectInactiveCheckbox",
                                  "type": "checkbox",
                                  "value": "${project.Inactive == 1}",
                                  "valueType": "bool"
                                }
  1. Then I reloaded the project in Radzen and created a new Change event in the "Events" tab:
    With the Type "Execute C#" and the code:

project.Inactive = args ? 1 : 0

The checkbox seems to be correctly interpreted and saved as 1 or 0 in the database, as soon I click the save button in the form:
Working_checkbox
The working configuration in the .json-file looks like this:

"components": [
{
  "events": {
	"change": [
	  {
		"code": "project.Inactive = args ? 1 : 0",
		"type": "execute"
	  }
	]
  },
  "name": "projectInactiveCheckbox",
  "type": "checkbox",
  "value": "${project.Inactive == 1}",
  "valueType": "bool"
}
],