Giter Site home page Giter Site logo

october-widgets / hasmany Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 4.0 456 KB

[READ ONLY] Subtree split of the HasMany widget (see october-widgets/library)

Home Page: http://github.com/october-widgets/library

PHP 34.02% CSS 13.94% JavaScript 38.20% HTML 13.84%

hasmany's Introduction

Hasmany

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.

hasmany's People

Contributors

scottbedard avatar

Stargazers

SINA avatar Wuri Nugrahadi avatar

Watchers

James Cloos avatar  avatar

hasmany's Issues

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.