nblum / silverstripe-customizableinputfield
SilverStripe form field for customizable input formats
Installs: 20
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 2
Open Issues: 2
Type:silverstripe-module
Requires
This package is auto-updated.
Last update: 2022-02-01 12:53:43 UTC
README
This package is deprecated. There will be no features or bug fixes in future.
Requirements
- Silverstripe 3.*
Installation
Composer
composer require "nblum/silverstripe-customizableinputfield"
Manual
- Download and copy module in SilverStripe root directory
Usage
Adding fields on a page
private static $db = array( 'Field' => 'CustomizableInputField' );
Example for mail address with pre defined domain:
_________ @example.com
//creates a new fieldset $field = new CustomizableInputFieldSet('Field', 'Email address'); //creates a new part $part1 = new CustomizableInputFieldPart(); $part1->setAfter('@example.com'); $part1->setMaxLength(15); $field->addPart($part1); //adds the customized fieldset to the tab $fields->addFieldToTab('Root.Main', $field, 'Content');
Example for (german) mobile phone numbers:
+49 (0) ___ / _________
//creates a new fieldset $field = new CustomizableInputFieldSet('Field', 'Mobile Phone'); //creates a new part $part1 = new CustomizableInputFieldPart(); //the first param will be visible in admin form, the second in the template $part1->setBefore('+49', '+49 (0)'); $part1->setAfter('/'); $part1->setMaxLength(3); $field->addPart($part1); //creates a second part $part2 = new CustomizableInputFieldPart(); $part2->setMaxLength(9); $field->addPart($part2); //adds the customized fieldset to the tab $fields->addFieldToTab('Root.Main', $field, 'Content');
Render values on a template
<!-- show the concatenated string for simple output --> <p>$Field1.Strval</p> <!-- loop over all parts of fieldset, for more individual output --> <p> <% loop $Field1.Parts %> <span>$Before $Value $After</span> <% end_loop %> </p>