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/filepicker_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 file picker elements.
30
 *
31
 * @copyright Meirza <meirza.arson@moodle.com>
32
 * @package   core_form
33
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
class test_filepicker_hideif_disabledif_form extends moodleform {
36
 
37
    /**
38
     * Form definition.
39
     */
40
    public function definition(): void {
41
        $mform = $this->_form;
42
 
43
        // Radio buttons.
44
        $radiogroup = [
45
            $mform->createElement('radio', 'some_radios', '', 'Enable', '1'),
46
            $mform->createElement('radio', 'some_radios', '', 'Disable', '2'),
47
            $mform->createElement('radio', 'some_radios', '', 'Hide', '3'),
48
        ];
49
 
50
        $mform->addGroup($radiogroup, 'some_radios_group', 'Enable/Disable/Hide', ' ', false);
51
        $mform->setDefault('some_radios', 1);
52
 
53
        $mform->addElement('filepicker', 'filepicker', 'File picker', null, ['accepted_types' => '*']);
54
 
55
        $mform->addElement('text', 'inputtext1', 'Disabled when the file picker has a file');
56
        $mform->setType('inputtext1', PARAM_RAW);
57
 
58
        $mform->addElement('text', 'inputtext2', 'Hidden when the file picker has a file');
59
        $mform->setType('inputtext2', PARAM_RAW);
60
 
61
        // Disabled the file picker by selecting the radio button.
62
        $mform->disabledIf('filepicker', 'some_radios', 'eq', '2');
63
 
64
        // Hide the file picker by selecting the radio button.
65
        $mform->hideIf('filepicker', 'some_radios', 'eq', '3');
66
 
67
        // Disabled the input text by uploading a file to the file picker.
68
        $mform->disabledIf('inputtext1', 'filepicker', 'noteq', '');
69
 
70
        // Hide the input text by uploading a file to the file picker.
71
        $mform->hideIf('inputtext2', 'filepicker', 'neq', '');
72
    }
73
}
74
 
75
$form = new test_filepicker_hideif_disabledif_form();
76
 
77
echo $OUTPUT->header();
78
$form->display();
79
echo $OUTPUT->footer();