GithubHelp home page GithubHelp logo

processwire-fieldtypeselectrelation's Introduction

WARNING: This repository is no longer maintained โš ๏ธ

This repository will not be updated. The repository will be kept available in read-only mode.

ProcessWire Fieldtype Select Relation

Overview:

This Fieldtype creates a select list (drop down) in relation to another field (you can restrict the list by setting up certain templates and / or pages).

Installation:

  1. Clone the module and place FieldtypeSelectRelation in your site/modules/ directory.
git clone https://github.com/justonestep/processwire-fieldtypeselectrelation.git your/path/site/modules/FieldtypeSelectRelation
  1. Login to ProcessWire admin and click Modules.
  2. Click "Check for new modules".
  3. Click "install" next to the new FieldtypeSelectRelation module.

Usage:

After installation, you'll have a new "Select" fieldtype that will allow you to define the items you'd like in the drop down depending on another field.

  • Create a new field and assign type SelectRelation
  • Click on the Details tab, there you find different fields to create your select list
    • Field: required, choose another field you created before from which the select list should be populated
    • Repeater: optional, if the field you chose is included in a repeater, select the repeater here
    • Template(s): optional, restrict your result by setting certain template(s)
    • Page(s): optional, restrict your result by setting certain page(s)
    • Unique Values: optional, check this field if you want to avoid duplicate values
      (If you enable this, the string value will be saved instead of the ID. You will not be able to reference via ID.)
    • Including not only visible pages: optional, include all hidden and unpublished pages and pages that user doesn't have access to view
    • Multiple Output: optional, multiple selection (using ASMSelect)

Unique Values Disabled

If this field is not enabled the key is the pages_id and the value is the value from the other field.

<select id="Inputfield_chosen_fruit" name="chosen_fruit">
  <option value=""></option>
  <option selected="selected" value="1026">Strawberry</option>
  <option value="1030">Apple</option>
  <option value="1031">Banana</option>
  <option value="1032">Lemon</option>
</select>

Note: If you change the value of a field the value changes too. If you deleted a value the value now is empty and multilingualism works like a charm.

Accessing the value:

// single select
echo $pages->get((int)$page->chosen_color)->color;

// multiple select
foreach ($page->chosen_color as $p) {
  echo $pages->get((int)$p)->color;
}

chosen_fruit and chosen_color are of the type SelectRelation.
title is the page title and color a simple input field (TextLanguage for example).

In chosen_fruit the selected field is title. And in chosen_color the selected field is color.

Unique Values Enabled

If this field is checked the key as well as the value are the value from the other field.

<select id="Inputfield_chosen_color" name="chosen_color">
  <option value=""></option>
  <option value="red">red</option>
  <option value="green">green</option>
  <option selected="selected" value="yellow">yellow</option>
</select>

If you don't check this box you might have duplicate colors (because there is more than one fruit which has a yellow color for example).
BUT if you change the value of an field, your already chosen value stays the same, because there isn't a relation via ID.

Access such a field like you are used to:

// single select
echo reset($page->chosen_color);

// multiple select
foreach ($page->chosen_color as $p) {
  echo $p;
}

Screens

Settings

Fields

TL;DR: I tried to save a comma separated list for duplicate values .It works until you change anything. For example, if you have two times the color yellow a key of the kind '1034,1036' may get saved. Now assume you change a basic color (the banana turns brown :D), the selected value is now empty because a key like '1034,1036' doesn't exist anymore. And in the frontend you may get a wrong output.

processwire-fieldtypeselectrelation's People

Contributors

justb3a avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

processwire-fieldtypeselectrelation'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.