Permalink
Browse files

MDL-30638 mod_choice: Add required elements to repeated form items

To make it work properly with MDL-30637
  • Loading branch information...
kabalin committed Feb 7, 2013
1 parent a4067bf commit 9d2a7df11b4480fe318b1ca57e5fdb6060c6ae3c
Showing with 5 additions and 20 deletions.
  1. +5 −20 mod/choice/mod_form.php
View
@@ -35,7 +35,7 @@ function definition() {
$menuoptions = array();
$menuoptions[0] = get_string('disable');
$menuoptions[1] = get_string('enable');
- $mform->addElement('header', 'timerestricthdr', get_string('limit', 'choice'));
+ $mform->addElement('header', 'limithdr', get_string('limit', 'choice'));
$mform->addElement('select', 'limitanswers', get_string('limitanswers', 'choice'), $menuoptions);
$mform->addHelpButton('limitanswers', 'limitanswers', 'choice');
@@ -59,8 +59,10 @@ function definition() {
$this->repeat_elements($repeatarray, $repeatno,
$repeateloptions, 'option_repeats', 'option_add_fields', 3);
-
-
+ // Make the first option required
+ if ($mform->elementExists('option[0]')) {
+ $mform->addRule('option[0]', get_string('atleastoneoption', 'choice'), 'required', null, 'client');
+ }
//-------------------------------------------------------------------------------
$mform->addElement('header', 'timerestricthdr', get_string('timerestrict', 'choice'));
@@ -116,23 +118,6 @@ function data_preprocessing(&$default_values){
}
- function validation($data, $files) {
- $errors = parent::validation($data, $files);
-
- $choices = 0;
- foreach ($data['option'] as $option){
- if (trim($option) != ''){
- $choices++;
- }
- }
-
- if ($choices < 1) {
- $errors['option[0]'] = get_string('atleastoneoption', 'choice');
- }
-
- return $errors;
- }
-
function get_data() {
$data = parent::get_data();
if (!$data) {

0 comments on commit 9d2a7df

Please sign in to comment.