简体   繁体   中英

How to customize $mform->createElement in moodle

$attr = "onChange = alert('hi');";
$objs = array();
        $objs[] =& $mform->createElement('select', $this->name.'_op', null,  '',$this->get_operators(), $attr);

The above is my code, here javascript not added in my select box.

Actually the moodle document says 4th parameter is value and 5th parameter is attributes, But the above code 5th parameter is value and attributes not working anywhere. How to customize createElement function.

The moodle and php version is upgraded from 5.6 to php 7.1 by another developer he left now, now this issue occur

jayavel

You are passing $attr at wrong number, 5th parameter is attribute parameter as per moodle doc https://docs.moodle.org/dev/lib/formslib.php_Form_Definition#select

Change your code from

 $objs[] =& $mform->createElement('select', $this->name.'_op', null,  '',$this->get_operators(), $attr);

to

$objs[] =& $mform->createElement('select', $this->name.'_op', null,  '', $attr);

By this way, you will get your javascript alert on change of select box data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM