owl/hasmany 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

owl/hasmany

Composer 安装命令:

composer require owl/hasmany

包简介

Has-many / belongs-to relation subforms.

README 文档

README

Has-many/belongs-to popup widget for OctoberCMS.

Packagist

Installation

To install the Hasmany widget, add the following to your plugin's composer.json file.

"require": {
    "owl/hasmany": "~1.0@dev"
}

Next, register the widget in your Plugin.php file.

public function registerFormWidgets()
{
    return [
        'Owl\FormWidgets\HasMany\Widget' => [
            'label' => 'Hasmany',
            'code'  => 'owl-hasmany'
        ],
    ];
}

Usage

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.

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.

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.

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.

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.

$(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.

统计信息

  • 总下载量: 784
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 5
  • 开发语言: JavaScript

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-01-30