I'm creating a website where users can select during registration what positions they play on the field using checkboxes. I have a 'Player Profiles' page to show the team.
I'm using the field rewrite to rewrite what the position is, but when I select "Hide if Empty" and "Count the number 0 as empty" the field is always displayed.
I did some digging and it seems to be trying to evaluate the output of the Boolean field as empty, but since it gets rewritten, it is never 0 or empty.
I added a new type of output 'raw' that will return the raw state of the checkbox and then it can be evaluated and hidden if necessary.
In views_handler_filter_boolean_operator.inc
function get_value_options() {
if (isset($this->definition['type'])) {
if ($this->definition['type'] == 'yes-no') {
$this->value_options = array(1 => t('Yes'), 0 => t('No'));
}
if ($this->definition['type'] == 'on-off') {
$this->value_options = array(1 => t('On'), 0 => t('Off'));
}
if ($this->definition['type'] == 'raw') {
$this->value_options = array(1 => 1, 0 => 0);
}
}
// Provide a fallback if the above didn't set anything.
if (!isset($this->value_options)) {
$this->value_options = array(1 => t('True'), 0 => t('False'));
}
}
And in
views_handler_field_boolean.inc
$form['type'] = array(
'#type' => 'select',
'#title' => t('Output format'),
'#options' => array(
'yes-no' => t('Yes/No'),
'true-false' => t('True/False'),
'on-off' => t('On/Off'),
'raw' => t('Raw'),
),
'#default_value' => $this->options['type'],
);
and
switch ($this->options['type']) {
case 'yes-no':
default:
return $value ? t('Yes') : t('No');
case 'true-false':
return $value ? t('True') : t('False');
case 'on-off':
return $value ? t('On') : t('Off');
case 'raw':
return $value;
}
Tried to create a patch, but still butchering it.
Comment | File | Size | Author |
---|---|---|---|
#12 | 702772-field_boolean-custom.patch | 2.49 KB | dawehner |
#8 | views_hide_if_empty.patch | 1.29 KB | dawehner |
#5 | views_hide_if_empty.patch | 1.38 KB | jjarvis98 |
Comments
Comment #1
jjarvis98 CreditAttribution: jjarvis98 commentedComment #2
jjarvis98 CreditAttribution: jjarvis98 commentedStill an issue with the latest version.
The code for views_handler_filter_boolean_operator.inc stays the same.
The code for views_handler_field_boolean.inc just needs to be changed to this:
Comment #3
dawehnerPlease create a patch.
See http://drupal.org/patch/create
Its not that hard :)
Comment #4
webservant316 CreditAttribution: webservant316 commentedThis thread was very helpful to me.
Unfortunately I do not have the handy tools to quickly make a patch myself either.
Here is what I did...I slight modification of the above.
In views_handler_filter_boolean_operator.inc insert at line 50
if ($this->definition['type'] == 'yes-0') {
$this->value_options = array(1 => t('Yes'), 0 => t('0'));
}
In views_handler_field_boolean.inc insert at line 34
'yes-0' => array(t('Yes'), t('0')),
This patch enabled me to choose not to display checkbox fields when they were 0 valued.
Comment #5
jjarvis98 CreditAttribution: jjarvis98 commentedUsing Views 6.x-3.0-alpha3.
Extract to your modules directory.
Save the patch file to your modules directory.
Comment #6
merlinofchaos CreditAttribution: merlinofchaos commentedSetting proper status for patches.
Comment #7
lhubbert CreditAttribution: lhubbert commentedThis did it for me, spent hours trying to figure out how to work around this very problem. Thanks so much!
Comment #8
dawehnerThis patch showed nothing in the field configuration see
Here is a new patch.
Comment #9
dawehnerThe rest :) looked fine.
Comment #10
bathizte CreditAttribution: bathizte commentedYou saved me quite some time with this patch .. Thanks !!
Comment #11
merlinofchaos CreditAttribution: merlinofchaos commentedQuestion: Would it be better to just have a "Custom" value that allows the user to enter the true/false values? That way it could easily be set to an empty string and 'hide if empty' would then work. It shouldn't be that hard to do this.
I think I would much rather see that than 'raw' which isn't all that useful to most people.
Comment #12
dawehnerHere is a patch for the custom part of the field.
Comment #13
liquidcms CreditAttribution: liquidcms commentedtitle says rewrite of fields is also part of this; but not sure from this if it is or if this patch ever got committed.
i had a site with an older rev of 6.2; but then updated to a Feb 2011 version of 2.x-dev when the site was being updated.. and now i have a view with a pile of fields that are rewritten empty fields.
i just grabbed latest 2.x-dev and no help.. so i'll assume that is this issue and update ver number here.
Comment #14
liquidcms CreditAttribution: liquidcms commentedmaybe title here is just wrong.. not sure rewrite has anything to do with this.. anyway.. my issue was resolved with this patch: http://drupal.org/node/1020540#comment-4417516 which sadly is not committed yet
Comment #15
webservant316 CreditAttribution: webservant316 commentedFYI - I am still depending upon my patch in #4 and so manually rolling it forward as I upgrade my Drupal install to Views 2.16.
Comment #16
tamarackmedia CreditAttribution: tamarackmedia commentedI think I was experiencing the same problem and here was my work around without using a patch (forgive me if this isn't actually addressing the issues above, but may be helpful to someone else.
I needed to provide a single checkbox with the active result being a re-write and the inactive result being nothing. Even with Count The Number 0 as Empty enabled, as described above, all nodes were displaying with the re-write.
I was using the simple checkbox widget. I changed to checkbox / radio buttons, added only one value to the available values field, and set options to unlimited, so I still had the checkbox. This allowed me to re-write those that were checked and exclude the rest from display.
Comment #17
Dropper CreditAttribution: Dropper commentedThank you very much! You just saved my day! I didn't enter any values for the single on/off checkbox (it said, it would enter 0 or 1). Now I have entered the 1 and 0 in the configuration fields and now views recognizes the 0 and the 1. Perfect!
Comment #18
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedThe Drupal 6 branch is no longer supported, please check with the D6LTS project if you need further support. For more information as to why this issue was closed, please see issue #3030347: Plan to clean process issue queue