2017 © Pedro Peláez
 

silverstripe-module extra-attributes-field

Extension of SilverStripe form fields to allow attributes for child elements on dropdown (option) and checkboxset (checkbox) fields.

image

exadium/extra-attributes-field

Extension of SilverStripe form fields to allow attributes for child elements on dropdown (option) and checkboxset (checkbox) fields.

  • Friday, December 18, 2015
  • by exadium
  • Repository
  • 1 Watchers
  • 6 Stars
  • 2,725 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 1 Versions
  • 6 % Grown

The README.md

Extra Attributes Field module

Description

Extension of SilverStripe form fields to allow adding attributes to child elements on dropdown and checkboxset fields., (*1)

Maintainer Contact

Marijn Kampf , (*2)

Exadium Web Development and Online Marketing. Visit http://www.exadium.com for more information., (*3)

Installation

composer require "exadium/extra-attributes-field":"*"

The module should work out of the box on a standard installation of SilverStripe. If you have Bootstrap Forms module installed by, (*4)

\extra-attributes-field\templates\ \themes\bootstrap\templates, (*5)

Usage

public function getCMSFields() {
    $fields = parent::getCMSFields();

    $count = array('1' => 'One', '2' => 'Two', '3' => 'Three');
    $batties = array('1' => 'Batty', '2' => 'Batty batty', '3' => 'Batty batty batty');

    $fields->push(
        DropdownAttributesField::create('DropdownAttributesCount', 'DropdownAttributesField Count', $count)
            ->setOptionsAttributes('data-bats', $batties)
    );

    $fields->push(
        CheckboxSetField::create('CheckCount', 'CheckboxSetField Count', $count)
            ->setOptionsAttributes('data-bats', $batties)
    );

    return $fields;
}

Generates code like, (*6)



Or you can load from a database field map. Also shows adding multiple options., (*7)

$fields->push(
    DropdownAttributesField::create('Members', 'Members', Member::get()->map('ID', 'Name'))
        ->setOptionsAttributes('data-email', Member::get()->map('ID', 'Email'))
        ->setOptionsAttributes('data-firstname', Member::get()->map('ID', 'FirstName'))
);

Notes

If you use silverstripe-bootstrap-forms copy BootstrapCheckboxSetField.ss to your templates folder. If you use your own custom Field templates add, (*8)

$OptionAttributesHTML 

to your input/option/checkbox/..., (*9)

Requirements

SilverStripe 3.1, (*10)

The Versions

18/12 2015

dev-master

9999999-dev https://github.com/marijnkampf/silverstripe-dropdown-attributes-field

Extension of SilverStripe form fields to allow attributes for child elements on dropdown (option) and checkboxset (checkbox) fields.

  Sources   Download

The Requires

 

module dropdown silverstripe field dropdownfield