Giter Site home page Giter Site logo

yvestrublin / silverstripe-quickaddnew Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sheadawson/silverstripe-quickaddnew

0.0 1.0 0.0 180 KB

A decorator for a form field that manages as has_one relation, to allow adding a new object on the fly

PHP 60.77% CSS 2.41% JavaScript 36.82%

silverstripe-quickaddnew's Introduction

silverstripe-quickaddnew

What is it?

A decorator for form fields that manage object relationships, to allow adding a new object on the fly through a dialog window. It can handle has_one, has_many or many_many relationships. At the moment it has been tested / works on DropdownField, ListboxField and CheckboxSetField. It works both in the CMS and in the frontend. For frontend, Select2Field or MultiSelect2Field are recommended.

Screenshot

Screenshot

Requirements

SilverStripe 3

Usage

Firstly, when creating the form field, we need to create a closure that returns the source array to populate the field's options. We do this because later on, when the field is refreshed with the newly created Object ID as it's value, we need to use this function Again to get up to date data for the source.

$source = function(){
	return MyObject::get()->map()->toArray();
};

Then we can create the form field, calling the closure as the source argument

$field = DropdownField::create('MyObjectID', 'My Object', $source());

Next, we can tell the field to use and configure quickaddnew. The first parameter is the class name of the object that will be created. The second is the $source closure Note: See QuickAddNewExtension::useAddNew() for the list of configurations parameters available. These allow you to customise the fields and required fields (for validation) for the dialog. By default the object class's getAddNewFields() or getCMSFields() methods are used

$field->useAddNew('MyObject', $source);

Add the field to your FieldList

$fields->addFieldToTab('Root.Main', $field);

silverstripe-quickaddnew's People

Contributors

sheadawson avatar wernerkrauss avatar yvestrublin avatar micschk avatar

Watchers

 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.