Exposed views filter + Allowed values for Computed Field - Possible?

flying_q - November 1, 2009 - 15:42
Project:Computed Field
Version:6.x-1.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

Hi All,

Has anyone had any success exposing a filter for a computed field, and turning this in to a selection box? For example - computed field outputs Monday, Tuesday, Wednesday, Thursday or Friday as an output. I would then like a user to be able to filter a view based on these values, but from a select box. Currently, it seems like support is only available for a text box entry.

Thanks

#1

flying_q - November 1, 2009 - 15:42
Title:Exposed views filter + Allowed values for Computer Field - Possible?» Exposed views filter + Allowed values for Computed Field - Possible?

#2

ESC - November 24, 2009 - 23:56

I've been trying to figure out the same thing for awhile and recently came up with something that seems to work.

1) I implemented the "mymodule_tools_form_views_exposed_form_alter" hook in a mini-module that I've created for various helper functions.

2) I placed the following code w/in the hook function:

  if ($form['myfieldname']) {
    $form['myfieldname']['#type'] = "select";
    $form['myfieldname']['#options'] = array(All=>"<All>",Yes=>"Yes",No=>"No");
    $form['myfieldname']['#default_value'] = No;
    $form['myfieldname']['#size'] = null;
  }

3) In the View's administration page, I set the "Value" field for the exposed computed field filter to "All".

The last step was necessary in order to clear an “An illegal choice has been detected. Please contact the site administrator.” error message that popped up on the View's display page otherwise. I should note that neither the default value property nor the "All" selection in the View definition affected the status of the HTML select field widget -- this was always set to the first value in the select list (in this case "All") on page load. However, after that everything seems to work normally.

This is actually the first time that I've implemented a Drupal hook, so if I'm doing anything wrong (or if there is a better way to approach the problem) I'd appreciate hearing about it.

I hope this helps!

#3

flying_q - December 1, 2009 - 21:34

ESC - thanks so much for the response....instead of using a computed field I was actually fortunate enough to use the tokens available from the Date module. I stripped the 'day' field from the date a user selected (via the really slick JS Calendar popup). At time of Node-save I just created a simple rule set that said save Day from Date into Field XYZ. I am then able to filter based on those values.

Regards.

#4

ESC - December 3, 2009 - 19:05

flying_q ,

Thanks for the info. I had also been thinking about something along the same lines as your approach, but still have a couple questions.

1) What type of field is "Field XYZ" in your example and does it have an allowed values list? I've only been able to get select lists for allowed values fields (as opposed to a select list of actual current field values).

2) Sounds like you are using the Rules module to implement the save-time action. Is that right?

Appreciate any more info on these questions.

Best

 
 

Drupal is a registered trademark of Dries Buytaert.