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 /** 18 * Test form for testing autocomplete behaviour. 19 * 20 * @copyright 2020 The Open University 21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 */ 23 24 require_once(__DIR__ . '/../../../../config.php'); 25 require_once($CFG->libdir . '/formslib.php'); 26 27 if (!defined('BEHAT_SITE_RUNNING')) { 28 throw new coding_exception('This fixture can only be used in Behat tests.'); 29 } 30 require_login(); 31 require_capability('moodle/site:config', context_system::instance()); 32 33 34 /** 35 * The form class for our test. 36 */ 37 class test_form extends moodleform { 38 39 protected function definition() { 40 $mform = $this->_form; 41 42 $mform->addElement('course', 'x', 'Controls the rest'); 43 44 $mform->addElement('text', 'enabledifblank', 'Single select will be enabled if the control is blank'); 45 $mform->disabledIf('enabledifblank', 'x', 'neq', ''); 46 $mform->setType('enabledifblank', PARAM_RAW); 47 48 $mform->addElement('text', 'disabledifblank', 'Single select will be disabled if the control is blank'); 49 $mform->disabledIf('disabledifblank', 'x', 'eq', ''); 50 $mform->setType('disabledifblank', PARAM_RAW); 51 52 $this->add_action_buttons(); 53 } 54 } 55 56 $PAGE->set_context(context_system::instance()); 57 $PAGE->set_url('/lib/form/tests/fixtures/autocomplete-disabledif.php'); 58 echo $OUTPUT->header(); 59 60 $form = new test_form(); 61 if ($data = $form->get_data()) { 62 echo $OUTPUT->notification("Data was submitted (but still re-showing form).", 'success'); 63 } 64 65 $form->display(); 66 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body