An editor is the user interface used to edit an entity and is made up of tabs and property editors.
Configuring an editor
The editor configuration is a sub configuration of a Collection
config builder instance and is accessing via it's Editor
method.
Editor(Lambda editorConfig = null) : KonstruktEditorConfig<TEntityType>
Accesses the editor config of the given collection.
Copy // Example
collectionConfig . Editor (editorConfig => {
.. .
});
Adding a tab to an editor
AddTab(string name, Lambda tabConfig = null) : KonstruktEditorTabConfigBuilder<TEntityType>
Adds a tab to the editor.
Copy // Example
editorConfig . AddTab ( "General" , tabConfig => {
.. .
});
A slidebar is a smaller area that is displayed to the right of the main editor. The sidebar can also contain fieldsets and fields in the same way tabs can but with a much more limited display area so you'll need to choose your field types carefully. The sidebar is a great location to display entity metadata.
Configures the sidebar for the tab.
Copy // Example
tabConfig . Sidebar (sidebarConfig => {
.. .
});
Setting the visibility of a tab
SetVisibility(Predicate<KonstruktEditorTabVisibilityContext> visibilityExpression) : KonstruktEditorTabConfigBuilder<TEntityType>
Sets the runtime visibility of the tab.
Copy // Example
tabConfig . SetVisibility (ctx => ctx . EditorMode == KonstruktEditorMode . Create );
Adding a fieldset to a tab
AddFieldset(string name, Lambda fieldsetConfig = null) : KonstruktEditorFieldsetConfigBuilder<TEntityType>
Adds the given fieldset to the tab.
Copy // Example
tabConfig . AddFieldset ( "Contact" , fieldsetConfig => {
.. .
});
Setting the visibility of a fieldset
SetVisibility(Predicate<KonstruktEditorFieldsetVisibilityContext> visibilityExpression) : KonstruktEditorFieldsetConfigBuilder<TEntityType>
Sets the runtime visibility of the fieldset.
Copy // Example
fieldsetConfig . SetVisibility (ctx => ctx . EditorMode == KonstruktEditorMode . Create );
Adding a field to a fieldset
AddField(Lambda propertyExpression, Lambda propertyConfig = null) : KonstruktEditorFieldConfigBuilder<TEntityType, TValueType>
Adds the given property to the editor.
Copy // Example
fieldsetConfig . AddField (p => p . FirstName , fieldConfig => {
.. .
});
Changing the label of a field
By default Konstrukt will build the label from the property name, including splitting camel case names into sentence case, however you can set an explicit label if you'd prefer.
SetLabel(string label) : KonstruktEditorFieldConfigBuilder<TEntityType, TValueType>
Sets the label for the editor field.
Copy // Example
fieldConfig . SetLabel ( "First Name" );
Hiding the label of a field
Sometimes you may have a field editor that would work better in full width, in which case you can achieve this by explicitly hiding the fields label.
HideLabel() : KonstruktEditorFieldConfigBuilder<TEntityType, TValueType>
Hides the label for the editor field.
Copy // Example
fieldConfig . HideLabel ();
Adding a description to a field
SetDescription(string description) : KonstruktEditorFieldConfigBuilder<TEntityType, TValueType>
Sets the description for the editor field.
Copy // Example
fieldConfig . SetDescription ( "Enter your age in years" );
Changing the data type of a field
By default Konstrukt will automatically choose a relevant data type for simple field types, however you can override this should you wish to use an alternative data type.
SetDataType(string dataTypeName) : KonstruktEditorFieldConfigBuilder<TEntityType, TValueType>
Set the data type of the current field to the Umbraco data type with the given name.
Copy // Example
fieldConfig . SetDataType ( "Richtext Editor" );
SetDataType(int dataTypeId) : KonstruktEditorFieldConfigBuilder<TEntityType, TValueType>
Set the data type of the current field to the Umbraco data type with the given id.
Copy // Example
fieldConfig . SetDataType ( - 88 );
Setting the default value of a field
SetDefaultValue(TValueType defaultValue) : KonstruktEditorFieldConfigBuilder<TEntityType, TValueType>
Sets the default value to a known constant.
Copy // Example
fieldConfig . SetDefaultValue ( 10 );
SetDefaultValue(Func defaultValueFunc) : KonstruktEditorFieldConfigBuilder<TEntityType, TValueType>
Sets the default value via a function that gets evaluated at time of entity creation.
Copy // Example
fieldConfig . SetDefaultValue (() => DateTime . Now );
Making a field required
MakeRequired() : KonstruktEditorFieldConfigBuilder<TEntityType, TValueType>
Makes the given field required.
Copy // Example
fieldConfig . MakeRequired ();
Validating a field
SetValidationRegex(string regex) : KonstruktEditorFieldConfigBuilder<TEntityType, TValueType>
Defines the regular expression to use when validating the field.
Copy // Example
fieldConfig . SetValidationRegex ( "[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}" );
Making a field read only
MakeReadOnly() : KonstruktEditorFieldConfigBuilder<TEntityType, TValueType>
Makes the current field read only disabling editing in the UI.
Copy // Example
fieldConfig . MakeReadOnly ();
MakeReadOnly(Func<TValueType, string> format) : KonstruktEditorFieldConfigBuilder<TEntityType, TValueType>
Makes the current field read only disabling editing in the UI. Provides a custom formatting expression to use when rendering the value as a string.
Copy // Example
fieldConfig . MakeReadOnly (distanceProp => $"{distanceProp : ## 'km'}" );
MakeReadOnly(object dataTypeNameOrId) : KonstruktEditorFieldConfigBuilder<TEntityType, TValueType>
Makes the current field read only disabling editing in the UI. Provides the name or id of a datatype to use when in readonly mode.
Copy // Example
fieldConfig . MakeReadOnly ( "myReadOnlyEditor" );
MakeReadOnly(Predicate<KonstruktEditorFieldReadOnlyContext> readOnlyExp) : KonstruktEditorFieldConfigBuilder<TEntityType, TValueType>
Makes the current field read only disabling editing in the UI if the given runtime predicate is true.
Copy // Example
fieldConfig . MakeReadOnly (ctx => ctx . EditorMode == KonstruktEditorMode . Create );
MakeReadOnly(Predicate<KonstruktEditorFieldReadOnlyContext> readOnlyExp, Func<TValueType, string> format) : KonstruktEditorFieldConfigBuilder<TEntityType, TValueType>
Makes the current field read only disabling editing in the UI if the given runtime predicate is true. Provides a custom formatting expression to use when rendering the value as a string.
Copy // Example
fieldConfig.MakeReadOnly(ctx => ctx.EditorMode == KonstruktEditorMode.Create, distanceProp => $"{distanceProp:## 'km'}");
MakeReadOnly(Predicate<KonstruktEditorFieldReadOnlyContext> readOnlyExp, object dataTypeNameOrId) : KonstruktEditorFieldConfigBuilder<TEntityType, TValueType>
Makes the current field read only disabling editing in the UI if the given runtime predicate is true. Provides the name or id of a datatype to use when in readonly mode.
Copy // Example
fieldConfig . MakeReadOnly (ctx => ctx . EditorMode == KonstruktEditorMode . Create , "myReadOnlyEditor" );
Setting the visibility of a field
SetVisibility(Predicate<KonstruktEditorFieldVisibilityContext> visibilityExpression) : KonstruktEditorFieldConfigBuilder<TEntityType, TValueType>
Sets the runtime visibility of the field.
Copy // Example
fieldConfig . SetVisibility (ctx => ctx . EditorMode == KonstruktEditorMode . Create );