Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
require_once(__DIR__ . '/../../../../config.php');
18
 
19
defined('BEHAT_SITE_RUNNING') || die();
20
 
21
global $CFG, $PAGE, $OUTPUT;
22
require_once($CFG->libdir . '/formslib.php');
23
$PAGE->set_url('/lib/form/tests/fixtures/multiselect_hideif_disabledif_form.php');
24
$PAGE->add_body_class('limitedwidth');
25
require_login();
26
$PAGE->set_context(core\context\system::instance());
27
 
28
/**
29
 * Test class for hiding and disabling elements dependent on a multi-select element.
30
 *
31
 * @package   core_form
32
 * @copyright 2024 Lars Bonczek (@innoCampus, TU Berlin)
33
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
class test_multiselect_hideif_disabledif_form extends moodleform {
36
 
37
    /**
38
     * Form definition.
39
     */
40
    public function definition(): void {
41
        $mform = $this->_form;
42
 
43
        $mform->addElement('select', 'multiselect1', 'multiselect1', [
44
            1 => 'Option 1',
45
            2 => 'Option 2',
46
        ], ['multiple' => true]);
47
 
48
        $mform->addElement('checkbox', 'disabledIfEq_', "Disabled if selection 'eq' []");
49
        $mform->addElement('checkbox', 'disabledIfIn_', "Disabled if selection 'in' []");
50
        $mform->addElement('checkbox', 'disabledIfNeq_', "Disabled if selection 'neq' []");
51
        $mform->addElement('checkbox', 'disabledIfEq1', "Disabled if selection 'eq' ['1']");
52
        $mform->addElement('checkbox', 'disabledIfIn1', "Disabled if selection 'in' ['1']");
53
        $mform->addElement('checkbox', 'disabledIfNeq1', "Disabled if selection 'neq' ['1']");
54
        $mform->addElement('checkbox', 'disabledIfEq12', "Disabled if selection 'eq' ['1', '2']");
55
        $mform->addElement('checkbox', 'disabledIfIn12', "Disabled if selection 'in' ['1', '2']");
56
        $mform->addElement('checkbox', 'disabledIfNeq12', "Disabled if selection 'neq' ['1', '2']");
57
 
58
        $mform->disabledIf('disabledIfEq_', 'multiselect1[]', 'eq', []);
59
        $mform->disabledIf('disabledIfIn_', 'multiselect1[]', 'in', []);
60
        $mform->disabledIf('disabledIfNeq_', 'multiselect1[]', 'neq', []);
61
        $mform->disabledIf('disabledIfEq1', 'multiselect1[]', 'eq', ['1']);
62
        $mform->disabledIf('disabledIfIn1', 'multiselect1[]', 'in', ['1']);
63
        $mform->disabledIf('disabledIfNeq1', 'multiselect1[]', 'neq', ['1']);
64
        $mform->disabledIf('disabledIfEq12', 'multiselect1[]', 'eq', ['1', '2']);
65
        $mform->disabledIf('disabledIfIn12', 'multiselect1[]', 'in', ['1', '2']);
66
        $mform->disabledIf('disabledIfNeq12', 'multiselect1[]', 'neq', ['1', '2']);
67
 
68
        $mform->addElement('checkbox', 'hideIfEq_', "Hide if selection 'eq' []");
69
        $mform->addElement('checkbox', 'hideIfIn_', "Hide if selection 'in' []");
70
        $mform->addElement('checkbox', 'hideIfNeq_', "Hide if selection 'neq' []");
71
        $mform->addElement('checkbox', 'hideIfEq1', "Hide if selection 'eq' ['1']");
72
        $mform->addElement('checkbox', 'hideIfIn1', "Hide if selection 'in' ['1']");
73
        $mform->addElement('checkbox', 'hideIfNeq1', "Hide if selection 'neq' ['1']");
74
        $mform->addElement('checkbox', 'hideIfEq12', "Hide if selection 'eq' ['1', '2']");
75
        $mform->addElement('checkbox', 'hideIfIn12', "Hide if selection 'in' ['1', '2']");
76
        $mform->addElement('checkbox', 'hideIfNeq12', "Hide if selection 'neq' ['1', '2']");
77
 
78
        $mform->hideIf('hideIfEq_', 'multiselect1[]', 'eq', []);
79
        $mform->hideIf('hideIfIn_', 'multiselect1[]', 'in', []);
80
        $mform->hideIf('hideIfNeq_', 'multiselect1[]', 'neq', []);
81
        $mform->hideIf('hideIfEq1', 'multiselect1[]', 'eq', ['1']);
82
        $mform->hideIf('hideIfIn1', 'multiselect1[]', 'in', ['1']);
83
        $mform->hideIf('hideIfNeq1', 'multiselect1[]', 'neq', ['1']);
84
        $mform->hideIf('hideIfEq12', 'multiselect1[]', 'eq', ['1', '2']);
85
        $mform->hideIf('hideIfIn12', 'multiselect1[]', 'in', ['1', '2']);
86
        $mform->hideIf('hideIfNeq12', 'multiselect1[]', 'neq', ['1', '2']);
87
 
88
        $this->add_action_buttons();
89
    }
90
}
91
 
92
$form = new test_multiselect_hideif_disabledif_form();
93
 
94
echo $OUTPUT->header();
95
$form->display();
96
echo $OUTPUT->footer();