---
title: Filtering form components
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

Form component filtering allows you to hide [form components](https://docs.kentico.com/13/developing-websites/form-builder-development/developing-form-components.md) from the form builder's [user interface](https://docs.kentico.com/13/managing-website-content/forms/composing-forms.md). For example, if you develop a custom version of one of the system's [default components](https://docs.kentico.com/13/developing-websites/form-builder-development/reference-system-form-components.md), you can help users choose the correct one by hiding the original.

## Creating filters

Form component filters are classes that implement the **IFormComponentFilter** interface and its **Filter** method. The method's parameters give you access to the following objects:

- **IEnumerable** – a collection of definitions representing the available form components. Each contains metadata under which the form component was [registered into the system](https://docs.kentico.com/13/developing-websites/form-builder-development/developing-form-components.md#registering-form-components), such as the _identifier_, _name_, or _description._
- **FormComponentFilterContext** – contains contextual information about the form being edited via the form builder interface, such as the form code name. You can use the information to provide a different set of components for specific forms.

The _Filter_ method needs to return the collection of the filtered form component definitions.

The following example filters all default Xperience form components from the form builder user interface.

```csharp

using System.Linq;
using System.Collections.Generic;

using Kentico.Forms.Web.Mvc;
using Kentico.Forms.Web.Mvc.FormComponents;

namespace LearningKit.FormBuilder
{
    public class FormComponentsFilter : IFormComponentFilter
    {
        public IEnumerable<FormComponentDefinition> Filter(IEnumerable<FormComponentDefinition> formComponents, FormComponentFilterContext context)
        {
            // Filters out all Xperience form components from the form builder UI
            return formComponents.Where(component => !component.Identifier.StartsWith("Kentico"));
        }
    }
}

```

You can also filter out individual Xperience form components by matching their identifiers with the **IDENTIFIER** constant exposed by each form component class. See [Reference - System form components](https://docs.kentico.com/13/developing-websites/form-builder-development/reference-system-form-components.md).

```csharp

using System.Linq;
using System.Collections.Generic;

using Kentico.Forms.Web.Mvc;
using Kentico.Forms.Web.Mvc.FormComponents;

namespace LearningKit.FormBuilder
{
    public class IndividualFormComponentsFilter : IFormComponentFilter
    {
        public IEnumerable<FormComponentDefinition> Filter(IEnumerable<FormComponentDefinition> formComponents, FormComponentFilterContext context)
        {
            // Filters specified form components
            return formComponents.Where(component => !GetComponentsToFilter().Contains(component.Identifier));
        }

        // A collection of form component identifiers to filter
        private IEnumerable<string> GetComponentsToFilter()
        {
            return new string[] { TextInputComponent.IDENTIFIER, TextAreaComponent.IDENTIFIER, USPhoneComponent.IDENTIFIER };
        }
    }
}

```

## Registering filters

Register filters by adding them to the **FormBuilderFilters.FormComponentFilters** collection on application start. For example, as part of [custom module initialization code](https://docs.kentico.com/13/custom-development/creating-custom-modules/initializing-modules-to-run-custom-code.md), or in your application's startup code.

Note that the filtering is cumulative. The process starts with a collection of all form components registered in the system. Each subsequently applied filter then works with the collection of form components returned (filtered) by the previous filter:

<!-- dev-model:mvc start -->

**MVC 5 development model.** Applies only when building with ASP.NET MVC 5. If this page also covers ASP.NET Core, that version is in its own block.

```csharp

using Kentico.Forms.Web.Mvc;

...

protected void Application_Start()
{
    ...

    RegisterFormComponentFilters();
}

private void RegisterFormComponentFilters()
{
    // Selectively hides default system form components
    FormBuilderFilters.FormComponents.Add(new IndividualFormComponentsFilter());

    // Hides all default system form components
    FormBuilderFilters.FormComponents.Add(new FormComponentsFilter());
}

```

<!-- dev-model:mvc end -->

<!-- dev-model:core start -->

**ASP.NET Core development model.** Applies only when building with ASP.NET Core. If this page also covers MVC 5, that version is in its own block.

```csharp title="Startup.cs"

using Kentico.Forms.Web.Mvc;

... 

protected void ConfigureServices() 
{ 
    ... 
    RegisterFormComponentFilters(); 
} 

private void RegisterFormComponentFilters() 
{ 
    // Selectively hides default system form components 
    FormBuilderFilters.FormComponents.Add(new IndividualFormComponentsFilter()); 
    // Hides all default system form components 
    FormBuilderFilters.FormComponents.Add(new FormComponentsFilter()); 
}

```

<!-- dev-model:core end -->

Registering filters that use dependency injection

Form component filter classes support [dependency injection](https://docs.kentico.com/13/developing-websites/initializing-xperience-services-with-dependency-injection.md) and their constructor can have parameters (e.g., instances of services registered in the project's DI container).

Such filters must be registered into the _FormBuilderFilters.FormComponentFilters_ collection using the **Add** method:

<!-- dev-model:mvc start -->

**MVC 5 development model.** Applies only when building with ASP.NET MVC 5. If this page also covers ASP.NET Core, that version is in its own block.

```csharp

using Kentico.Forms.Web.Mvc;

...

protected void Application_Start()
{
    ...

    RegisterFormComponentFilters();
}

private void RegisterFormComponentFilters()
{
    // Selectively hides default system form components
    FormBuilderFilters.FormComponents.Add<IndividualFormComponentsFilter>();

    // Hides all default system form components
    FormBuilderFilters.FormComponents.Add<FormComponentsFilter>();
}

```

<!-- dev-model:mvc end -->

<!-- dev-model:core start -->

**ASP.NET Core development model.** Applies only when building with ASP.NET Core. If this page also covers MVC 5, that version is in its own block.

```csharp title="Startup.cs"

using Kentico.Forms.Web.Mvc;

... 

protected void ConfigureServices() 
{ 
    ... 
    RegisterFormComponentFilters(); 
} 

private void RegisterFormComponentFilters() 
{ 
    // Selectively hides default system form components 
    FormBuilderFilters.FormComponents.Add<IndividualFormComponentsFilter>(); 
    // Hides all default system form components 
    FormBuilderFilters.FormComponents.Add<FormComponentsFilter>(); 
}

```

<!-- dev-model:core end -->
