The following function in views/modules/views_profile.inc
/**
* Display a profile field of type 'checkbox', view as tick mark
*/
function views_handler_field_profile_checkbox($fieldinfo, $fielddata, $value, $data) {
$value = (unserialize($value) === false) ? $value : unserialize($value);
return (check_plain($value) == '0') ? '& #10007;' : '& #10003;';
}
attempts to display the checkbox state with specialized Unicode characters:
- BALLOT X — http://www.fileformat.info/info/unicode/char/2717/index.htm
- CHECK MARK — http://www.fileformat.info/info/unicode/char/2713/index.htm
Unfortunately these characters are not available on normal WinXP computers. Firefox displays question marks and IE displays boxes, and there is no way to distinguish the checked and unchecked states.
It's a cute idea, but even if the characters were available, using the BALLOT X to denote an empty checkbox is a bit misleading, because BALLOT X looks much more like a checked checkbox than an empty one (depending on your visual style).
I'd suggest using this instead:
return (check_plain($value) == '0') ? '[ ]' : '[X]';
This results in either of
- [ ]
- [X]
and it's what the attached patch does — it doesn't look too bad IMO. If you care about accessibility, you'd probably use 'No'/'Yes' instead.
P.S. The PHP filter preserves the   entity, but not the numeric ones, so I had to fiddle a bit to get the code to display properly. It looks as intended on my FF, but maybe not on your browser...
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | views_profile.checkbox.070906b.patch.txt | 694 bytes | salvis |
| #1 | views_profile.checkbox.070906.patch.txt | 709 bytes | salvis |
| views.checkbox.patch.txt | 704 bytes | salvis |
Comments
Comment #1
salvisIt turns out that checkbox data is not always set. For example a private profile checkbox field may have no record in the profile_values table, and testing for '0' results in displaying the checkbox as checked when it's not set!
gives the correct result.
Comment #2
merlinofchaos commentedDoes just empty($value) work?
Comment #3
salvisWe want to display a boolean value, either Checked or Unchecked, I guess. The question is what we do with NULL (no record for that field in the profile_values table). I haven't checked whether
check_plain($value)actually returns NULL or an empty string, but we don't want to display three states, do we?The old code (aside of using non-displayable characters) displayed the Checked token for NULL, which is counter-intuitive, and my code displays the Unchecked token instead.
I would prefer to always have either 0 or 1 in the database, but profile.module doesn't work that way, not even for checkboxes that do appear on the registration form. It could be argued that this is a bug in profile.module, but there are also the private profile fields, and we probably have to accept that these are not set when the registration form is submitted, so we have to deal with NULL.
P.S. You write
but you seem to be working on D6 in the MAIN branch now.
Comment #4
merlinofchaos commentedThat message is quite old. I clearly must update it.
We want to display a boolean value, either Checked or Unchecked, I guess. The question is what we do with NULL (no record for that field in the profile_values table). I haven't checked whether check_plain($value) actually returns NULL or an empty string, but we don't want to display three states, do we?
This is why I suggested empty() -- it will return false for 0, '' and NULL.
Comment #5
salvisOk, I tried
It gives me
The line in #1 works just fine...
Comment #6
merlinofchaos commentedUgh, don't check_plain it before running it through empty() -- that's silly. Just empty($value).
Comment #7
salvisYes, that works nicely. :-)
Comment #8
mgiffordI just checked to see if this function exists views_handler_field_profile_checkbox() in D6 or D7. Since it doesn't I'm closing it.