From f19ff3ec2dfcaab984a123e980916c1e409694e8 Mon Sep 17 00:00:00 2001 From: Shea Dawson Date: Sat, 13 Sep 2014 16:31:47 +1000 Subject: [PATCH] Update README.md --- README.md | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index da6cfb6..e131e20 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,23 @@ A silverstripe dropdown field that has it's options populated via ajax, based on SilverStripe 3 -##Usage +##Usage example -TODO! +```php +// 1. Create a callable function that returns an array of options for the DependentDropdownField. When the value of the field it depends on changes, this function is called passing the updated value as the first parameter ($val) +$datesSource = function($val){ + if($val == 'one'){ + // return appropriate options array if the value is one. + } + if($val == 'two'){ + // return appropriate options array if the value is two. + } +}; + +$fields = FieldList::create( + // 2. Add your first field to your field list, + $fieldOne = DropdownField::create('FieldOne','Field One', array('one' => 'One', 'two' => 'Two'), + // 3. Add your DependentDropdownField, setting the source as the callable function you created and setting the field it depends on to the appropriate field + DependentDropdownField::create('FieldTwo','Field Two', $datesSource)->setDepends($fieldOne) +); +```