本文整理匯總了PHP中MoodleQuickForm::updateElementAttr方法的典型用法代碼示例。如果您正苦於以下問題:PHP MoodleQuickForm::updateElementAttr方法的具體用法?PHP MoodleQuickForm::updateElementAttr怎麽用?PHP MoodleQuickForm::updateElementAttr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類MoodleQuickForm
的用法示例。
在下文中一共展示了MoodleQuickForm::updateElementAttr方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: mform_autocomplete
/**
* Add autocomplete to a form text field
*
* @param MoodleQuickForm $mform Moodle form
* @param array|moodle_url $options Array of autocomplete options, if $hiddenfieldname is
* passed, array indexes are considered record IDs
* @param string $textfieldname The text field's name
* @param string $hiddenfieldname The hidden field's name. If passed,
* the option index will be set to this hidden
* value when its option value is selected in
* the text field
* @param string $width The pixel width of the text field (Due to YUI, must
* use width instead of size)
* @return void
* @link http://developer.yahoo.com/yui/examples/autocomplete/ac_basic_array.html What you get with no $hiddenfieldname
* @link http://developer.yahoo.com/yui/examples/autocomplete/ac_itemselect.html What you get with $hiddenfieldname
*/
public function mform_autocomplete($mform, $options, $textfieldname, $hiddenfieldname = '', $width = '300')
{
global $PAGE;
$url = NULL;
$data = NULL;
// Generate data source
if ($options instanceof moodle_url) {
$url = $options->out(false);
} else {
$data = array();
foreach ($options as $optionid => $option) {
if (empty($hiddenfieldname)) {
$data[] = $option;
} else {
$data[] = (object) array('text' => $option, 'id' => $optionid);
}
}
}
$fields = array('text');
if (!empty($hiddenfieldname)) {
$fields[] = 'id';
}
$module = array('name' => 'local_mr_framework', 'fullpath' => '/local/mr/framework/assets/javascript.js', 'requires' => array('yui2-yahoo', 'yui2-dom', 'yui2-event', 'yui2-datasource', 'yui2-json', 'yui2-connection', 'yui2-get', 'yui2-animation', 'yui2-autocomplete'));
$arguments = array((object) array('fieldname' => $textfieldname, 'hiddenfieldname' => $hiddenfieldname, 'width' => $width, 'url' => $url, 'data' => $data, 'fields' => $fields));
$PAGE->requires->js_init_call('M.local_mr.init_mr_html_autocomplete', $arguments, true, $module);
// $PAGE->requires->css('/lib/yui/2.8.1/build/autocomplete/assets/autocomplete-core.css');
// $PAGE->requires->css('/lib/yui/2.8.1/build/autocomplete/assets/skins/sam/autocomplete.css');
// Update form - need to force some attributes and add the javascript
$mform->updateElementAttr($textfieldname, array('autocomplete' => 'off', 'style' => "width: {$width}px;"));
// Add ID to hidden field so javascript can find it
if (!empty($hiddenfieldname)) {
$mform->updateElementAttr($hiddenfieldname, array('id' => "id_{$hiddenfieldname}"));
}
}
示例2: get_settings
/**
* Get the settings form for Mahara submission plugin
*
* @global stdClass $CFG
* @global stdClass $DB
* @param MoodleQuickForm $mform The form to add elements to
* @return void
*/
public function get_settings(MoodleQuickForm $mform)
{
global $CFG;
require_once $CFG->dirroot . '/mod/assign/submission/mahara/lib.php';
if ($hosts = assignsubmission_mahara_sitelist()) {
$hostid = $this->get_config('mnethostid');
if ($hostid === false) {
// No setting for this instance, so use the sitewide default
$hostid = get_config('assignsubmission_mahara', 'host');
}
$locked = $this->get_config('lock');
if ($locked === false) {
// No setting for this instance, so use the sitewide default
$locked = get_config('assignsubmission_mahara', 'lock');
}
// Menu to select which MNet host
$mform->addElement('select', 'assignsubmission_mahara_mnethostid', get_string('site', 'assignsubmission_mahara'), $hosts);
$mform->setDefault('assignsubmission_mahara_mnethostid', $hostid);
$mform->disabledIf('assignsubmission_mahara_mnethostid', 'assignsubmission_mahara_enabled', 'notchecked');
// Menu to select whether to lock Mahara pages or not
$locksettings = array(ASSIGNSUBMISSION_MAHARA_SETTING_DONTLOCK => new lang_string('no'), ASSIGNSUBMISSION_MAHARA_SETTING_KEEPLOCKED => new lang_string('yeskeeplocked', 'assignsubmission_mahara'), ASSIGNSUBMISSION_MAHARA_SETTING_UNLOCK => new lang_string('yesunlock', 'assignsubmission_mahara'));
$mform->addElement('select', 'assignsubmission_mahara_lockpages', get_string('lockpages', 'assignsubmission_mahara'), $locksettings);
$mform->setDefault('assignsubmission_mahara_lockpages', $locked);
$mform->addHelpButton('assignsubmission_mahara_lockpages', 'lockpages', 'assignsubmission_mahara');
$mform->disabledIf('assignsubmission_mahara_lockpages', 'assignsubmission_mahara_enabled', 'notchecked');
} else {
// No hosts found.
$mform->addElement('static', 'assignsubmission_mahara_mnethostid', get_string('site', 'assignsubmission_mahara'), get_string('nomaharahostsfound', 'assignsubmission_mahara'));
$mform->updateElementAttr('assignsubmission_mahara_enabled', array('disabled' => true));
}
$mform->addHelpButton('assignsubmission_mahara_mnethostid', 'site', 'assignsubmission_mahara');
}