Skip to content

Latest commit

 

History

History
112 lines (79 loc) · 2.45 KB

forms.md

File metadata and controls

112 lines (79 loc) · 2.45 KB

Ways to customize forms.

Show/Hide Fields

protected override IEnumerable<string> ShownFormControlNames {
  // explicit fields
}

protected override IEnumerable<string> HiddenFormControlNames {
  // hidden fields  
} 

Read-only Fields

someFormControl.IsReadOnly = true; 

GenerateFormControls Methods

The GenerateFormControls methods are the main way to customize the form fields generated for Create and Edit pages.

There are a few overload options:

// Basic signature
protected override IEnumerable<FormControlViewModel> GenerateFormControls(
  TEntity entity, 
  EntityAction action,
  IDictionary<string, string> entityDict)

// With option filters  
protected override IEnumerable<FormControlViewModel> GenerateFormControls(
  TEntity entity,
  EntityAction action, 
  IDictionary<string, string> entityDict,
  IDictionary<string, Expression<Func<object, bool>>> optionFilters)  

// Async version  
protected override async Task<IEnumerable<FormControlViewModel>> GenerateFormControlsAsync(...)

The methods return a collection of FormControlViewModel representing each form control.

Default Implementation

By default, it creates controls for:

  • Primitive properties like strings, numbers.
  • Navigation properties as dropdowns loaded from DbSets.

This requires no customization for basic cases.

Customizing Defaults

You can customize the defaults like:

Hide fields

protected override IEnumerable<string> HiddenFormControlNames { 
  // fields to hide
}

Show only certain fields

protected override IEnumerable<string> ShownFormControlNames {
  // fields to show
} 

Make fields read-only

formControl.IsReadOnly = true;

Adding Custom Controls

To add completely custom controls, create and add FormControlViewModel instances:

protected override IEnumerable<FormControlViewModel> GenerateFormControls() 
{
  // Create custom control
  var ratingControl = new FormControlViewModel();
  
  // Add to default fields
  return base.GenerateFormControls().Concat(new[] { ratingControl });
}

Overriding Completely

For full control, override GenerateFormControls and explicitly build the controls:

protected override IEnumerable<FormControlViewModel> GenerateFormControls()
{
  return new FormControlViewModel[]
  {
     // Explicitly build controls
  };
}

Let me know if you need any clarification or have additional questions!