#10556 closed enhancement (wontfix)
Add a checked_array() to compare arrays like checked()
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.9 |
Component: | Template | Keywords: | needs-patch |
Focuses: | Cc: |
Description
The checked() function checks whether two parameters passed to it are equal and then outputs checked='checked', which can be used in forms having checkboxes or radio buttons.
Sometimes (particularly for checkboxes), we might need to check for multiple values. So I am proposing a change to the checked() function.
It can first check whether the default value is an array and if yes, it can return checked='checked' if the current value is present in the default array.
I have attached a patch with this change.
Attachments (3)
Change History (16)
#1
@
16 years ago
- Keywords reporter-feedback added; checked template removed
- Owner set to westi
- Status changed from new to accepted
Could you give a more detailed example of what you are trying to do that the checked function doesn't support.
An example simple plugin which has an page with a check box on would be fine.
I would like to get a clear understanding of the issue that presents.
#2
@
16 years ago
- Cc sudar@… added
Here is a scenario which explains what I am try to do.
Let's say I am writing a Plugin, which is displaying all top level pages (as checkboxes) and the user will be selecting some of them. I will have the name of the checkboxes as an array (eg: selected_pages[]), so that I can easily handle the post variables when the form is submitted.
Now the next time, when the page is displayed, I have to keep the checkboxes that were already selected as checked. I will have the selected pages as an array, and instead of looping through every time to find out whether the current page is there in the array or not, I can pass the current id and the array to the checked function which can print checked='checked', if the current page id is present in the array.
I have attached a small Plugin to demonstrate this.
(sorry for the delay in reply, I didn't noticed the status change)
#4
@
16 years ago
- Keywords reporter-feedback removed
- Summary changed from Ability to compare arrays in checked() function to Add a checked_array() to compare arrays like checked()
#5
@
16 years ago
Updated the template patch according to the principles in the plugin. Original code had repeated parts I was able to remove. There is no need for an additional function, checked() and selected() accepted already arrays based on their definition (they converted them to strings which does not make sense).
#7
@
16 years ago
- Keywords needs-patch added; has-patch removed
I like neither patches, personally. On the one hand side, we're checking using the === operator, whereas on the other we're using in_array(), which amounts to using the == operator.
the === was introduced in order to distinguish an empty string from a numerical zero.
#9
@
15 years ago
- Cc shidouhikari added
So, we can´t use in_array() because of the operstor?
That's sad, I liked the 2nd patch.
hakre, I believe the (string) is meant for ints, and not for arrays.
#11
@
15 years ago
- Milestone changed from Awaiting Triage to Future Release
- Owner changed from westi to nacin
patch for checked function