Coder Social home page Coder Social logo

helpfulrobot / nblum-silverstripe-customizableinputfield Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nblum/silverstripe-customizableinputfield

0.0 2.0 0.0 11 KB

License: MIT License

PHP 45.80% Scheme 7.32% CSS 8.98% JavaScript 37.90%

nblum-silverstripe-customizableinputfield's Introduction

silverstripe-customizableinputfield

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>
    

nblum-silverstripe-customizableinputfield's People

Contributors

nblum avatar

Watchers

James Cloos avatar helpfulrobot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.