Moodle
  1. Moodle
  2. MDL-8886

Add new "in" condition for $mform->disabledIf in Moodle forms

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.9
    • Fix Version/s: None
    • Component/s: Forms Library
    • Labels:
      None
    • Affected Branches:
      MOODLE_19_STABLE
    • Rank:
      11895

      Description

      I would like to be able to disable a "text" field depending on the value of an associated "select" field.

      Here is some sample code to use for testing.

      • locate the following line "mod/chat/mod_form.php" (around line 48)
        $this->standard_coursemodule_elements();
      • insert the following code just before the above line
        $mform->addElement('header', 'testsection', 'Test Section');
        $HOTPOT_FEEDBACK = array (
        0 => get_string("feedbacknone", "hotpot"),
        1 => get_string("feedbackwebpage", "hotpot"),
        2 => get_string("feedbackformmail", "hotpot"),
        3 => get_string("feedbackmoodleforum", "hotpot"),
        4 => get_string("feedbackmoodlemessaging", "hotpot")
        );
        $mform->addElement('select', 'studentfeedback', 'Student Feedback', $HOTPOT_FEEDBACK);
        $mform->addElement('text', 'studentfeedbackurl', 'Student Feedback URL');
        $mform->disabledIf('studentfeedbackurl', 'studentfeedback', 'in', '0,3,4');
      • locate the following lines in "lib/javascript-static.js" (around line 99)
        case 'noitemselected':
        lock = master.selectedIndex==-1; break;
      • insert the following code just after the above lines
        case 'in':
        lock = false;
        var values = value.split(',');
        for (var i in values)
        Unknown macro: { if (values[i]==master.options[master.selectedIndex].value) { lock = true; } }

        break;

      • login to Moodle as a teacher/admin
      • add a "Chat" activity in the course and view the fields on the "Adding a Chat" page
        (you may need to "force-refresh" the page, Ctrl+F5, to get the new javascript file to load)

      This allows the text field to be used to take extra information for certain values of the select field, and I believe it would prove useful in other situation beyond the example above which is taken from the HotPot module.

      thanks in advance for considering this option
      Gordon

        Activity

        Gordon Bateson created issue -
        Jamie Pratt made changes -
        Field Original Value New Value
        Attachment javascript-static.js.patch [ 11027 ]
        Jamie Pratt made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Martin Dougiamas made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        QA Assignee nobody
        Martin Dougiamas made changes -
        Workflow jira [ 19857 ] MDL Workflow [ 55330 ]
        Martin Dougiamas made changes -
        Workflow MDL Workflow [ 55330 ] MDL Full Workflow [ 84438 ]

          People

          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: