nblum / silverstripe-customizableinputfield

此包已被弃用且不再维护。未建议任何替代包。

SilverStripe 可自定义格式的表单字段

安装: 20

依赖: 0

建议: 0

安全: 0

星星: 3

关注者: 1

分支: 2

开放问题: 2

类型:silverstripe-module

dev-master 2016-12-08 22:47 UTC

This package is auto-updated.

Last update: 2022-02-01 12:53:43 UTC


README

此包已弃用。未来将不会有新功能或错误修复。

需求

  • Silverstripe 3.*

安装

Composer

  • composer require "nblum/silverstripe-customizableinputfield"

手动

  • 下载并复制模块到 SilverStripe 根目录

用法

在页面上添加字段

    private static $db = array(
        'Field' => 'CustomizableInputField'
    );

预定义域名的邮件地址示例

_________ @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');
            

(德语)手机号码示例

+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');
            

在模板中渲染值

    <!-- 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>