2017 © Pedro Peláez
 

silverstripe-module silverstripe-hiddenfields

Takes form fields specified through $hidden_fields and hides them from edit form.

image

svandragt/silverstripe-hiddenfields

Takes form fields specified through $hidden_fields and hides them from edit form.

  • Thursday, April 14, 2016
  • by svandragt
  • Repository
  • 1 Watchers
  • 0 Stars
  • 14 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

silverstripe-hiddenfields

Takes form fields you specified through $hidden_fields and hides them from the edit form. I found if you completely remove the field then the value doesn't get saved to the database and you end up with child without a parent relationship., (*1)

Instead this extension replaces the field with a hiddenfield., (*2)

Usage

  1. Install using composer composer require "svandragt/silverstripe-hiddenfields:*"
  2. Attach the DataExtension to your DataObjects / Page types through the configuration system:
Object::add_extension("DataObject","HiddenFieldsDataExtension");

DIY Demo:

Course.php:, (*3)

<?php
class Course extends DataObject {
    public static $db = array(
        'Title'             => 'Varchar(500)',
    );

    public static $has_many = array(
        'CourseDates'        => 'CourseDate',
    );  

}

CourseDate.php:, (*4)

<?php
class CourseDate extends DataObject {
    public static $db = array(
        'StartDate' => 'Date',
        'EndDate'   => 'Date',
    );

    public static $has_one = array(
        'Course' => 'Course'
    );

    public static $hidden_fields = array(
        'CourseID'
    );

}

CourseModelAdmin.php:, (*5)

<?php

class CourseModelAdmin extends ModelAdmin {
    public static $managed_models = array(
        'Course', 
        'CourseDates',
    ); 
    static $url_segment = 'courses'; // Linked as /admin/products/
    static $menu_title = 'Course Admin';

}

Do a /dev/build and create a new course in the CMS. After saving, when accessing the CourseDates tab, you will not see the option to select the Course related to the dates (it is automatically saved from the parent - child relationship in this case)., (*6)

The Versions

14/04 2016

dev-master

9999999-dev

Takes form fields specified through $hidden_fields and hides them from edit form.

  Sources   Download

BSD-3-Clause

The Requires

 

model silverstripe fields hidden