Jump to content

Simple Dropdown/Checkbox List?


MatthewSchenker
 Share

Recommended Posts

Greetings Everyone,

I've been making great progress with ProcessWire -- really enjoying the way it works.

But there is one area I'm still a bit puzzled by, and I've put off posting about it in hopes that I'd have that "eureka" moment. But it hasn't happened yet, so I must post what may soon seem like a very simple question:

How do I create a dropdown field or a checkbox list?

I see how to create a single checkbox. But in my case, I have a "Galleries" form, where the user selects one of these gallery types:

- Master Artist

- Emerging Artist

- Virtual Exhibition

I could of course just have three different single checkboxes, which actually works well for making selections later (1 or 0 state).

I've searched the forum, but must admit I still don't quite see how dropdowns are created. Can someone shed some more light on this?

Thanks,

Matthew

Link to comment
Share on other sites

Hi MatthewSchenker,

you can create a page (gallerytypes) and these page have some childs. In this case you gallery types.

- gallerytypes

- - Master Artist

- - Emerging Artist

- - Virtual Exhibition

If you need this checkbox for the backend do the following:

Create a new field, type must be "page". Save this. In the next step you can set the input for your field. (Input -> Selectable Pages)

If you need these categories in your frontend use this code:

<select>
<?php
$categories = $pages->get("/gallerytypes/")->children;
foreach($categories as $category){
 echo '<option value="'. $category->id .'">'. $category->title .'</option>';
}
<select>

y.
?>
  • Like 2
Link to comment
Share on other sites

Greetings yesjoar,

Thanks for the help! I am probably accustomed to creating dropdowns from other CMSs, which I admit do not use the best practices when you look deeper and see the way the material goes into the database. I have read Ryan's explanation for doing dropdowns differently in ProcessWire, and I'm glad to know that he is not afraid to push for a proper way to get material into the database -- even if it requires a few extra steps.

Since I will probably have lots of dropdowns on my sites, I'm thinking the best way to manage this is to create a parent in my page tree for "Dropdowns" and then branch off individual dropdowns from there with children/grandchildren.

Thanks again,

Matthew

Link to comment
Share on other sites

Greetings diogo,

After reading up a bit more on the subject, I do realize that even though it is more involved, we are better off with the way Ryan sees dropdowns. If a site factors to something larger, I definitely see the benefit in being able to control what goes in/out using the page system.

I do think this is a very good example of how one can get so used to a weaker way of doing things (other CMSs) that when you come to a stronger system (ProcessWire) it at first appears to be weird. But then you realize how it works.

Still, I must admit that at the moment I'm still getting used to doing dropdowns/checkbox lists this way.

Thanks,

Matthew

Link to comment
Share on other sites

Further if you create those "category" pages, that will make the options, somewhere in your site structure you can even use those same pages to display galleries that belong to that particular category and you don't need to create such pages. Later you could add an image or description to those pages to display.

So like this

/galleries/categories/master-artist/

Would be also a viewable page and list all galleries that have that category selected.

It goes hand in hand and requires only minimal code at the end. Need a new option? Create a new Page there and you're done.

(wow so many replies already while writing this :))

  • Like 1
Link to comment
Share on other sites

Thinking about this, maybe it would make sense to create a special field that would allow doing this without changing the way PW works. Look at the repeaters field for instance, all it does is create one new normal page for each entry (they are just hidden). Maybe it would be even enough to extend the Page FieldType to allow creating those pages from the field options.

Link to comment
Share on other sites

I must admit to struggling to get my head around the idea of using pages for everything though I think it's more to do with just how they're displayed in the page tree. It makes complete sense to have them use the same structure but I don't really want to see everything in the tree.

Perhaps there could be a way of adding a checkbox with a template (or a page) when creating it where it stores the page under a separate heading at the bottom of the tree (perhaps styled differently with CSS).

The more I think of it, the more I think this would be perfect as it would still be a page but you wouldn't have to see:

Home

About

Blog

Contact

Fonts

Settings

Form options.

Perhaps something more like

Home

About

Blog

Contact

------------

Extra settings

Settings

Fonts

Form options

Link to comment
Share on other sites

It makes complete sense to have them use the same structure but I don't really want to see everything in the tree.

Create an "Options" page under "Admin" and hide it from searches (so it won't appear in the admin menu) and use it to organize all your options for the system:

post-88-0-59277700-1354107420_thumb.png

You will even forget they are in the tree

  • Like 1
Link to comment
Share on other sites

Thanks Diogo, good idea. I may try that though it's sort of the other extreme. I'm afraid clients will completely not know they are there!

I think I may do something in CSS but that would mean it would have to be hardcoded...

EDIT: Though I could of course just make them normal pages under a page called "Options" or "settings" I suppose. I just like the idea of styling them slightly differently. Maybe a different colour, italic etc...

Link to comment
Share on other sites

The clients don't even need to see those pages. If you check "Allow new pages to be created from field?" on the field options, they will be able to create new pages on the field itself.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...