Skip to content
This repository has been archived by the owner on Jan 28, 2019. It is now read-only.

attitude/field-link

Repository files navigation

Link Field for Cockpit

Proposal for Links field. Experimental, please use with caution.

This field requires Cockpit Next (right now current version is in COCOPi project).

Allows you to link collections with other collections (has many & has one relationship) in one direction (parent to child).

You can also specify which colelctions to link (single or multiple) or create children from parent and link them automatically.

Autocomplete Mode:

Autocomplete

List Mode:

List

Installation

$ cd cockpit/modules/addons
$ git clone [email protected]:attitude/field-link.git

Note: Directory must be named field-link for Cockpit to register addon.

Usage

In collection fields edit mode set LINK as field type.

Update tag: $npm run build requires riot pre-compiler to be installed on working machine.

Options:
Paramenter Type Description
placeholder string Replaces default Add Link... placeholder
collections string|array Sets which collections to link, not set by default, meaning any existing collection can be linked
hasOne boolean Forces one-to-one relationship, default is false
createNew string Collection slug for new entries, not set by default
list boolean List and filter available collections to link (disables autocomplete)

Examples

Add Beer... placeholder, collections attr as string, creates new entry for beers inline.

{
    "placeholder": "Add Beer...",
    "collections": "beers",
    "createNew": "beers"
}

Add drink... placeholder, allow multiple collections, attr as comma separated values:

{
    "placeholder": "Add Drink...",
    "collections": "beers, wines, coffees"
}

Add drink... placeholder, allow multiple collections, attr as array values:

{
    "placeholder": "Add Drink...",
    "collections": ["beers", "wines", "coffees"]
}

Restrict to single country:

{
    "placeholder": "Add Country...",
    "collections": "countries",
    "hasOne": true
}

Creating new entries inline

By default, child link must exist prior the linking. You can however use createNew attribute to create new children while editing parent.

Set createNew attribute, e.g. {"createNew": "beers"}, where beers is existing collection slug. New child will be create using Ajax.

New link is created with name and title attributes set as the input value. Newly created _id is than pushed into the link array.

Examples

Allows to create new car brands:

{
    "placeholder": "Add Cars...",
    "collections": "cars",
    "createNew": "cars"
}

Known Issues

  1. Autocomplete needs reload to trigger for links created inline to work properly
  2. Tested on Chrome

Feel free to test it and let me know @martin_adamko how works for you. Feel free to open issue if you find one.

Enjoy!

About

Link field for Cockpit CMS (Next)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published