Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
Spone committed Feb 3, 2023
1 parent a7e3a62 commit 64944a0
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ This allows you to pick the namespace your components will be loaded from.
# lib/custom_form_builder.rb
class CustomFormBuilder < ViewComponent::Form::Builder
# Set the namespace you want to use for your own components
namespace Custom::Form
namespace "Custom::Form"
end
```

Expand All @@ -116,7 +116,32 @@ bin/rails generate vcf:builder AnotherCustomFormBuilder --namespace AnotherCusto
# app/forms/another_custom_form_builder.rb
class AnotherCustomFormBuilder < ViewComponent::Form::Builder
# Set the namespace you want to use for your own components
namespace AnotherCustom::Form
namespace "AnotherCustom::Form"
end
```

Another approach is to include only some modules instead of inheriting from the whole class:

```rb
# app/forms/modular_custom_form_builder.rb
class ModularCustomFormBuilder < ActionView::Helpers::FormBuilder
# Provides `render_component` method and namespace management
include ViewComponent::Form::Renderer

# Exposes a `validation_context` to your components
include ViewComponent::Form::ValidationContext

# All standard Rails form helpers
include ViewComponent::Form::Helpers::Rails

# Backports of newest Rails form helpers
# include ViewComponent::Form::Helpers::RailsBackports

# Additional form helpers provided by ViewComponent::Form
# include ViewComponent::Form::Helpers::Custom

# Set the namespace you want to use for your own components
namespace "AnotherCustom::Form"
end
```

Expand Down

0 comments on commit 64944a0

Please sign in to comment.