Opened 15 years ago
Closed 15 years ago
#8481 closed enhancement (wontfix)
Improved version of checked() in template.php
Reported by: | chmac | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
function psu_checked($checked, $current) { if ( (is_array($current) && in_array($checked, $current)) || $checked == $current) echo ' checked="checked"'; }
instead of
function checked( $checked, $current) { if ( $checked == $current) echo ' checked="checked"'; }
Attachments (2)
Change History (11)
#3
@
15 years ago
- Keywords needs-patch added; has-patch removed
- Milestone changed from 2.8 to Future Release
patch needs a refresh against trunk
#4
@
15 years ago
- Keywords has-patch added; needs-patch removed
- Milestone changed from Future Release to 2.8
Ok, patch against the new code in trunk.
I've switched the milestone back to 2.8, not sure if I'm supposed to change it or not, but figured I'd give it a whirl. :-)
#5
@
15 years ago
I considered submitting an updated patch along those lines before bumping to Future.
Possible issues I foresaw:
- Should $current and $test be documented as accepting anything?
- If so, and if the is_array() check is not first, the $current == $test may end up being erroneously true with the new usage. Probably irrelevant, but it did have me thinking twice.
Just FYI...
+1 to the patch with updated phpdoc (i.e. accepts numeric/bool/string, different behavior with array).
#6
@
15 years ago
I've updated the patch, amended the phpdocs and switched the order around.
I think it makes more sense to say if (is_array($selected)) because that way you can have an array of selected values and mark each one as checked / selected. It probably doesn't make sense to mark multiple values selected but I'll leave that alone for now.
This function allows for an array of checked values to be passed which is useful in repetitive functions where an array of values are checked, but the array is not in any particular order.