![]() |
|
sfDoctrineChoiceChainPlugin - 1.1.1symfony choice chain plugin |
|
![]() |
11
users
Sign-in
to change your status |
Adds sfWidgetFormDoctrineChoiceChain widget and sfValidatorChoiceChain and provides a sfChoiceChain module to work handle widget XHR-requests. jQuery dependant. |
Provides a helpful sfWidgetFormDoctrineChoiceChain widget with the corresponding validator and module
| Name | Status | |
|---|---|---|
|
|
lead | moc.liamg <<ta>> kuydar.yexela |
Copyright (c) 2004-2006 Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
| Version | License | API | Released |
|---|---|---|---|
| 1.1.1stable | MIT license | 1.1.0stable | 30/11/2010 |
| 1.0.5.2stable | MIT license | 1.0.5.2stable | 27/09/2010 |
| Version | License | API | Released |
|---|---|---|---|
| 1.1.1stable | MIT license | 1.1.0stable | 30/11/2010 |
| 1.0.5.2stable | MIT license | 1.0.5.2stable | 27/09/2010 |
Array
Array
Array
The sfDoctrineChoiceChainPlugin is a symfony plugin that provides the ability to create a chain of dependant select elements that regenerate their options list depending on your choice
It gives you sfWidgetFormDoctrineChoiceChain widget plus the corresponding sfValidatorChoiceChain validator plus module to handle XHR requests
Install the plugin (via a package)
symfony plugin:install sfDoctrineChoiceChainPlugin
Publish plugin assets
symfony plugin:publish-assets
Enable the plugin module
all:
.settings:
enabled_modules: [default, sfChoiceChain]
Clear your cache
symfony cc
Suppose you have the following schema:
Country:
columns:
name: {type: string(255), notnull: true}
Region:
columns:
country_id: {type: integer, notnull: true}
name: {type: string(255), notnull: true}
relations:
Country: {local: country_id, foreign: id, onDelete: CASCADE, foreignAlias: Regions}
City:
columns:
region_id: {type: integer, notnull: true}
name: {type: string(255), notnull: true}
is_capital: {type: boolean, default: false}
relations:
Region: {local: region_id, foreign: id, onDelete: CASCADE, foreignAlias: Cities}
Location:
columns:
name: {type: string(255), notnull: true}
country_id: {type: integer}
region_id: {type: integer}
city_id: {type: integer}
#here goes more fields
relations:
Country: {local: country_id, foreign: id, onDelete: CASCADE, foreignAlias: Locations}
Region: {local: region_id, foreign: id, onDelete: CASCADE, foreignAlias: Locations}
City: {local: city_id, foreign: id, onDelete: CASCADE, foreignAlias: Locations}
You want your visitors to create new locations and you want them to choose first country, then load the country regions and then the cities
In your form
$this->widgetSchema['location'] = new sfWidgetFormDoctrineChoiceChain(array(
'chain' => array('Country', 'Region', 'City')
));
$this->validatorSchema['location'] = new sfValidatorChoiceChain(array(
'chain' => array('Country', 'Region', 'City')
));
This will give you 3 select elements, changing the values of each you will get the next one refilled with new values
To see more sophisticated examples you will have to enabled sfChoiceChainExample module that goes with the plugin
Enable an example module all: .settings: enabled_modules: [default, sfChoiceChain, sfChoiceChainExample]
Copy yaml schema from sfChoiceChainExample/config/schema.yml to your project schema.yml file and build model and forms
symfony doctrine:build --model --forms
Copy model classes from sfChoiceChainExample/lib/model to your model directory, existing model will be overwritten
Run sfChoiceChainExample.sql from sfChoiceChainExample/data. It is preferable to run this script rather than insert sql generated from schema, as it has all neccessary data included
Clear symfony cache and go to /sfChoiceChainExample to check out the scene
All posible widget/validator configurations are displayed in sfChoiceChainExample/lib/form/PluginTestItemForm.class.php, see configure method. updateObject and updateDefaultsFromObject methods will give you an example of dealing with the data and offsetGet method enables separate rendering.
