Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bootstrap Forms for SilverStripe 6

Makes SilverStripe 6 frontend forms render Bootstrap 5 markup automatically. No per-site template work: install, flush, done. The module ships no CSS or JS; it assumes the site already loads Bootstrap 5.

Requirements

  • PHP 8.3+
  • silverstripe/framework ^6.0
  • silverstripe/admin ^3.0

Installation

Add the package to the project's composer repositories (private package), then:

composer require anytech/bootstrap-forms

Run a flush (/dev/build?flush=1 or ?flush=1) so the template manifest picks up the overrides.

What it does

Two extensions applied via _config/extensions.yml:

  • FormFieldExtension on SilverStripe\Forms\FormField: appends Bootstrap classes to the rendered element through the updateAttributes hook, so holder wrapper classes stay untouched.
  • FormExtension on SilverStripe\Forms\Form: exposes $MessageAlertClass to templates, mapping form message types to alert-danger, alert-success, alert-info, alert-warning.

Template overrides in templates/SilverStripe/Forms/ replace the framework defaults (module templates outrank silverstripe/framework in the $default theme set; site themes still outrank this module):

Template Change
Includes/Form.ss Form message as .alert with role="alert", actions in .btn-toolbar.gap-2
FormField_holder.ss .mb-3 wrapper, .form-label, .invalid-feedback, .form-text
CheckboxField_holder.ss .form-check wrapper with .form-check-label
CheckboxField_holder_small.ss .form-check variant for field groups
OptionsetField.ss / CheckboxSetField.ss li.form-check with .form-check-input / .form-check-label
OptionsetField_holder.ss / CheckboxSetField_holder.ss fieldset wrapper with the group title as legend.col-form-label.pt-0, plus feedback/description blocks

Field class mapping:

Field Class
Text-like fields, textarea, file, date/time form-control
DropdownField, GroupedDropdownField, ListboxField form-select
CheckboxField form-check-input
OptionsetField, CheckboxSetField (the ul) list-unstyled
FormAction btn plus default variant
Any field with a validation message is-invalid

Skipped entirely: HiddenField, dataless fields (literal, header, label), GridField, TreeDropdownField, SearchableDropdownField, SearchableMultiDropdownField, and everything rendered inside the CMS (guarded by a LeftAndMain controller check; the cms-forms admin theme also outranks these templates in the admin).

Configuration

Default button variant is btn-primary. Change it per site:

Anytech\BootstrapForms\FormFieldExtension:
  button_variant: btn-outline-secondary

Per-action variants win over the default: any action that already carries a btn-* class (via addExtraClass) keeps it and the default variant is not added.

Overriding

A site theme template at themes/<theme>/templates/SilverStripe/Forms/... overrides this module as usual.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages