History | Log In     View a printable version of the current page.  
We are currently focused especially on Moodle 2.0, Moodle 1.9.x bugs and Moodle 1.9.x testing.    Confused? Lost? Please read this introduction to the Tracker.
Issue Details (XML | Word | Printable)

Key: MDL-14728
Type: Bug Bug
Status: Resolved Resolved
Resolution: Not a bug
Priority: Major Major
Assignee: Eloy Lafuente (stronk7)
Reporter: Mark Duffy
Votes: 0
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
Moodle

Other Fields Not Setting Required Field

Created: 07/May/08 09:31 PM   Updated: 17/May/08 06:16 PM
Component/s: Administration
Affects Version/s: 1.9
Fix Version/s: None

File Attachments: None
Image Attachments:

1. editadvanced-page.jpg
(80 kb)

2. user_profile.jpg
(94 kb)

Database: MySQL
Participants: Eloy Lafuente (stronk7), John T. Macklin and Mark Duffy
Security Level: None


 Description  « Hide
I'm using Moodle 1.9. I cant see anything in the tracker for this. The other fields in the custom profile fields is not setting fields as required. They dont change to red and no one gets prompted that its a required field.


 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Mark Duffy - 07/May/08 09:39 PM - edited
See Screenshot: Set as Required. Not required on Edit Advanced Page or Email signup page.

Mark Duffy - 07/May/08 09:39 PM - edited
See Screenshot: Field set as Required.

Eloy Lafuente (stronk7) - 08/May/08 12:51 AM
Hi Mark,

if I'm not wrong that's because you are editing user profiles as admin, and that role has permissions to update any user profile bypassing the "required" property.

But for normal users... the required property will be enforced.

Closing this as not a bug.

Thanks for the report, feel free to comment/reopen it if necessary.

Ciao :-)

John T. Macklin - 15/May/08 04:43 AM
Recently I had this issue on one of our sites... I have come up with a quick fix
which has been tested with Custom (menu) Lists only. In this instance the Admin wanted to force the Student to select an option from a custom menu field. I have verified this modification works on 1.8 and up. Most of the problems I have seen involving this is not actually a Moodle bug but a matter
of implementing validation using Pear HTML_QuickForm_Rules.

Here is what I came up with for user profiles (./user/edit.php) . This will
force any custom menu field to include a select one option by default and
enable required validation on that field.

File: ./user/edit.php
Affects Validation Behavior for element: profile_field_Otherfields
Affects Validation JScript: validate_user_edit_form_profile_field_Otherfields(element)

Notes:
5/14/2008: Fixed Custom Field List Box Validation (required) behavior.

FileName: ./lib/pear/HTML/QuickForm/RuleRegistry.php (Starting Line 284)

} elseif ($element->getType() == 'select') {
if ($element->getMultiple()) {
$elementName .= '[]';
$value =
" value{$jsIndex} = new Array();\n" .
" var valueIdx = 0;\n" .
" for (var i = 0; i < frm.elements['{$elementName}'].options.length; i++) {\n" .
" if (frm.elements['{$elementName}'].options[i].selected) {\n" .
" value{$jsIndex}[valueIdx++] = frm.elements['{$elementName}'].options[i].value;\n" .
" }\n" .
" }\n";
} else {
 $value = " value{$jsIndex} = frm.elements['{$elementName}'].selectedIndex == 0? '': frm.elements['{$elementName}'].options[frm.elements['{$elementName}'].selectedIndex].value;\n";
}

Make sure First Option of Custom Lists are of type Select-One:

FileName: ./usr/profile/field/menu/field.class.php (Line 12-28)

/*
* Make sure Custom Lists are Zero Indexed
* with Select-One list type behavior.
* JTM wink
*/


function profile_field_menu($fieldid=0, $userid=0) {
//first call parent constructor
$this->profile_field_base($fieldid, $userid);

/// Param 1 for menu type is the options
$options = explode("\n", $this->field->param1);
$this->options = array();
$this->options[-1]="Select one"; // Default List option for validation Select-One.
foreach($options as $key => $option) {
$this->options[$key] = format_string($option);//multilang formatting
}

/// Set the data key
if ($this->data !== NULL) {
$this->datakey = (int)array_search($this->data, $this->options);
}
}


Eloy Lafuente (stronk7) - 17/May/08 06:16 PM
Adding Jamie and Petr here to see the proposed patch above about enforcing required menus... they are the specialists in that area....