Why has no one written a choose_from_menu_yesno() before

Why has no one written a choose_from_menu_yesno() before

by Tim Hunt -
Number of replies: 6
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
This is so obvious, I am hesitant about checking this in. There must be a reason why it has not been done, but seach the code for variable with names like $yesno, to see how useful this function could be.

Should I just stop worrying and check this in?

Index: lib/weblib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/weblib.php,v
retrieving revision 1.617
diff -u -r1.617 weblib.php
--- lib/weblib.php 27 Aug 2006 21:52:22 -0000 1.617
+++ lib/weblib.php 30 Aug 2006 15:06:30 -0000
@@ -759,6 +759,16 @@
}

/**
+ * Choose value 0 or 1 from a menu with options 'No' and 'Yes'.
+ * Other options like choose_from_menu.
+ */
+function choose_from_menu_yesno($name, $selected, $script = '',
+ $return = false, $disabled = false, $tabindex = 0) {
+ return choose_from_menu(array(get_string('no'), get_string('yes')), $name,
+ $selected, '', $script, '0', $return, $disabled, $tabindex);
+}
+
+/**
* Just like choose_from_menu, but takes a nested array (2 levels) and makes a dropdown menu
* including option headings with the first level.
*/

Average of ratings: -
In reply to Tim Hunt

Re: Why has no one written a choose_from_menu_yesno() before

by Mark Nielsen -
Hi Tim,

I like the function smile  Might want to add the ability to change Yes and No strings.  So you could say, True/False, Enabled/Disabled, etc.

Cheers,
Mark
In reply to Mark Nielsen

Re: Why has no one written a choose_from_menu_yesno() before

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
....hide/show, on/off.... which possibly explains why it has never been coded. There are so many of these binary choices.
In reply to Howard Miller

Re: Why has no one written a choose_from_menu_yesno() before

by Michael Champanis -
Could pass them in as parameters; function ..(..$yes='yes', $no='no'...) {
In reply to Howard Miller

Re: Why has no one written a choose_from_menu_yesno() before

by Mark Nielsen -
That's why I suggested having the option to set those strings in the function call (as Michael has demonstrated).
In reply to Mark Nielsen

Re: Why has no one written a choose_from_menu_yesno() before

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
If you want custom fields, use the standard select_from_menu. yes/no seemed a sufficiently common case that it seemed worth doing a fuction for.
In reply to Tim Hunt

Re: Why has no one written a choose_from_menu_yesno() before

by David Scotson -
I believe it's an accessibility good practice to have such binary options presented as a checkbox, where the true/false, enabled/disabled, yes/no-ness is suggested by the associated title.