Name Mon Lu

Love jQuery/CSS

Blog about Webdev

Twitter supawaza

RSS Twitter Flickr

What I am up to:


Soft­ware note: Pods CMS Ver­sion 1.7.3 / WP 2.8.4

Doc­u­men­ta­tion: http://pods.uproot.us/codex/helpers

What are Input Helpers

An Input Helper lets you com­pletely cus­tomize the appear­ance of any input field… when adding new data contents.

In plain n00b Eng­lish: as an exam­ple, the default field “name” I had it to store last names, and a sep­a­rate col­umn to store first names (fname). The prob­lem of that would be when you’re using Bi-directional rela­tion­ship PICK col­umn to another Pod (let’s call this: Per­son) is you can only relate one of the columns, not both First Name and Last Name. So if you use the PICK col­umn the “name”; which stores the Last Names, and with the last name like John­son – you prob­a­bly can’t tell which John­son that is. Input Helpers can grab and dis­play the full names for you when you’re adding data. See screen­shot:

input-helper-fullname

How to add a new Input Helper

add-new-helper

Cus­tomized Drop­down Input Helper

The fol­low­ing refers back to the exam­ple and screen­shot above where it pulls full names from the “name” and “fname”columns as a PICK col­umn to dis­play as a drop down menu:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<select class="form pick1 <?php echo $name; ?>">
        <option value="">-- Select one --</option>
<?php
        if (!empty($value))
        {
            foreach ($value as $key => $val)
            {
                $lastname = $val['name'];
                $firstname = $val['firstname'];
                $fullname = $lastname.", ".$firstname;
                $selected = empty($val['active']) ? '' : ' selected';
?>
        <option value="<?php echo $val['id']; ?>"<?php echo $selected; ?>><?php echo $fullname; ?></option>
<?php
            }
        }
?>
    </select>

The cru­cial parts:

<select class="form pick1 <?php echo $name; ?>">

The class “form pick1″ are required by the default CSS unless you don’t care about the CSS. The $name is just an column’s name to iden­tify the column’s name. Just like Dis­play Helper, it passes the $value array for you to manip­u­late. The rest of the codes are very straight for­ward to read through the $value array, make sure that it actu­ally have some­thing in it before read­ing it. Then split it in parts to dis­play. The $select is sim­ply default select what­ever pre­vi­ous selected when you are brows­ing exist­ing con­tent. If you’re adding new con­tent, it is default to “–Select one–”. The very last part of this script is just sim­ply dis­play­ing each option, giv­ing each of them their unique row ID, then finally dis­play­ing the full names.

Another one I ran into was when I want to do a Multi PICK col­umn, such as peo­ple who belong to a Dojo or Fed­er­a­tion. See below:

input-helper-fullname2

I ref­er­enced the code above, with the help of Fire­Bug, this saved the day:

Cus­tomized Multi PICK Col­umn Input Helper

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<div class="form pick <?php echo $name; ?>">
<?php
        if (!empty($value))
        {
            foreach ($value as $key => $val)
            {
                $lastname = $val['name'];
                $firstname = $val['firstname'];
                $fullname = $lastname.", ".$firstname;
                $active= empty($val['active']) ? '' : ' active';
?>
       <div class="option<?php echo $active; ?>" value="<?php echo $val['id']; ?>"><?php echo $fullname ; ?></div>
<?php
            }
        }
?>
</div>

As you’ve noticed, there are only minor dif­fer­ences between the two. The dif­fer­ences are “div” instead of “select”, $active, and the very last line (line 12). Obvi­ously the very last line is the default CSS that used by Pods CMS for Multi PICK columns, unless you want some­thing different.

Using the helpers

Sim­ply click on the pencil/Edit icon of the col­umn, and choose the helper. Like this:

using-input-helper

Well, that’s it for now. I’ll update this sec­tion if I learn more.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • email
  • Ping.fm
  • Reddit
  • RSS
  • StumbleUpon
  • Technorati
  • Twitter

Related Posts

No related posts.

This entry was posted on Friday, September 25th, 2009 at 5:31 PM and is filed under Pods CMS, Web Dev. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

No Responses to “Pods CMS — Input Helpers”