Moodle

Other Fields Not Setting Required Field

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Not a bug
  • Affects Version/s: 1.9
  • Fix Version/s: None
  • Component/s: Administration
  • Labels:
    None
  • Database:
    MySQL
  • Affected Branches:
    MOODLE_19_STABLE

Description

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.

Activity

Hide
Mark Duffy added a comment - - edited

See Screenshot: Set as Required. Not required on Edit Advanced Page or Email signup page.

Show
Mark Duffy added a comment - - edited See Screenshot: Set as Required. Not required on Edit Advanced Page or Email signup page.
Hide
Mark Duffy added a comment - - edited

See Screenshot: Field set as Required.

Show
Mark Duffy added a comment - - edited See Screenshot: Field set as Required.
Hide
Eloy Lafuente (stronk7) added a comment -

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

Show
Eloy Lafuente (stronk7) added a comment - 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
Hide
John T. Macklin added a comment -

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);
}
}

Show
John T. Macklin added a comment - 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); } }
Hide
Eloy Lafuente (stronk7) added a comment -

Adding Jamie and Petr here to see the proposed patch above about enforcing required menus... they are the specialists in that area....

Show
Eloy Lafuente (stronk7) added a comment - Adding Jamie and Petr here to see the proposed patch above about enforcing required menus... they are the specialists in that area....
Hide
Anthony Borrow added a comment -

After looking at the code, I'm with Eloy on this one that it is not a bug but instead a feature for the admin. At first, when I was looking at the code I didn't see why the user capability would matter but Eloy's explanation makes sense to me. So I think this is my second time for claiming that this is a feature, not a bug There was some discussion about this at http://moodle.org/mod/forum/discuss.php?d=102814 and I've encouraged those users to comment here. Peace - Anthony

Show
Anthony Borrow added a comment - After looking at the code, I'm with Eloy on this one that it is not a bug but instead a feature for the admin. At first, when I was looking at the code I didn't see why the user capability would matter but Eloy's explanation makes sense to me. So I think this is my second time for claiming that this is a feature, not a bug There was some discussion about this at http://moodle.org/mod/forum/discuss.php?d=102814 and I've encouraged those users to comment here. Peace - Anthony

People

Vote (0)
Watch (4)

Dates

  • Created:
    Updated:
    Resolved: