dev-master
9999999-dev http://github.com/october-widgetsHas-many / belongs-to relation subforms.
MIT
The Requires
- php >=5.4.0
by Scott Bedard
owl october october cms hasmany
Wallogit.com
2017 © Pedro Peláez
Has-many / belongs-to relation subforms.
Has-many/belongs-to popup widget for OctoberCMS., (*1)
, (*2)
To install the Hasmany widget, add the following to your plugin's composer.json file., (*3)
"require": {
"owl/hasmany": "~1.0@dev"
}
Next, register the widget in your Plugin.php file., (*4)
public function registerFormWidgets()
{
return [
'Owl\FormWidgets\HasMany\Widget' => [
'label' => 'Hasmany',
'code' => 'owl-hasmany'
],
];
}
First things first, you'll need to have a pair of models related via a has-many / belongs-to relationship. From there, in your parent model's fields.yaml file use the relationship name as the field name, and owl-hasmany as the type., (*5)
relationship:
type: owl-hasmany
Next, you'll need to define the default parameters, or a custom partial. The default parameters will create a list that is very similar to the Sitemap plugin's UI. You may use basic twig markup inside these fields, variable names will reference model attributes. The icon option should be a valid Font-Autumn icon class, or false., (*6)
relationship:
type: owl-hasmany
default:
icon: icon-file-o
label: "{{ name }}"
comment: "{{ description }}"
To customize the widget appearance, you may also define a custom partial instead of the default., (*7)
relationship:
type: owl-hasmany
partial: @/plugins/author/plugin/models/relationship/_partial.htm
There are a few additional parameters available to customize the widget's appearance. Defining a sortColumn enables drag-and-drop re-ordering. This value should reference the model's "order by" column name. Defining a formHeader will change the default header of popup windows. Defining an addLabel or addIcon will customize the appearance of the add button. addLabel., (*8)
Javascript events will be triggered when a popup window is opened or closed. Listening for these events can be useful when you wish to show / hide fields based on form values., (*9)
$(document).bind("owl.hasmany.opened", function(e, data) {
// popup was opened
});
$(document).bind("owl.hasmany.closed", function(e, data) {
// popup was closed
});
The data array will contain 3 keys. data.alias refers to the widget alias, data.item refers to the popup's cooresponding li element, and data.form references the popup form element., (*10)
Has-many / belongs-to relation subforms.
MIT
owl october october cms hasmany