Permalink
Browse files

MDL-56640 js: yui to jquery for formautosubmit in select templates

I did not keep the 'nothing' behaviour in the js because I don't think
the nothing option needs special handling, given that its default
selection.
  • Loading branch information...
danpoltawski committed Oct 28, 2016
1 parent c67e93b commit 588b84f78ae4807685cce3fd03c282680176d0cf
Showing with 9 additions and 26 deletions.
  1. +2 −9 lib/outputcomponents.php
  2. +4 −11 lib/templates/single_select.mustache
  3. +3 −6 lib/templates/url_select.mustache
View
@@ -939,11 +939,11 @@ public function export_for_template(renderer_base $output) {
$data->name = $this->name;
$data->method = $this->method;
$data->action = $this->method === 'get' ? $this->url->out_omit_querystring(true) : $this->url->out_omit_querystring();
$data->classes = 'autosubmit ' . $this->class;
$data->classes = $this->class;
$data->label = $this->label;
$data->disabled = $this->disabled;
$data->title = $this->tooltip;
$data->formid = $this->formid;
$data->formid = !empty($this->formid) ? $this->formid : html_writer::random_id('single_select_f');
$data->id = !empty($attributes['id']) ? $attributes['id'] : html_writer::random_id('single_select');
unset($attributes['id']);
@@ -975,8 +975,6 @@ public function export_for_template(renderer_base $output) {
} else {
$options = $this->options;
}
$data->hasnothing = $hasnothing;
$data->nothingkey = $hasnothing ? key($nothing) : false;
foreach ($options as $value => $name) {
if (is_array($options[$value])) {
@@ -1247,9 +1245,6 @@ public function export_for_template(renderer_base $output) {
unset($attributes['title']);
$data->showbutton = $this->showbutton;
if (empty($this->showbutton)) {
$data->classes .= ' autosubmit';
}
// Select options.
$nothing = false;
@@ -1263,8 +1258,6 @@ public function export_for_template(renderer_base $output) {
$nothing = $this->nothing;
}
}
$data->hasnothing = !empty($nothing);
$data->nothingkey = $data->hasnothing ? key($nothing) : false;
$data->options = $this->flatten_options($this->urls, $nothing);
// Label attributes.
@@ -30,8 +30,6 @@
* formid - optional id value for the form.
* id - id for the element.
* params - array of params with name and value attributes.
* hasnothing - true if element has no options.
* nothingkey - nothing key to be set.
* options - Array of options for the select with value, name , slected and optgroup properites.
* labelattributes - Label attributes.
* helpicon - Help icon.
@@ -41,7 +39,7 @@
"name": "lang",
"method": "get",
"action": "http://localhost/stable_master/mod/scorm/player.php",
"classes": "autosubmit langmenu",
"classes": "langmenu",
"label": "Zombies are coming...",
"disabled": false,
"title": null,
@@ -65,8 +63,6 @@
"value": "eXeMapADrive4823c6301cf72b22b72"
}
],
"hasnothing": false,
"nothingkey": false,
"options": [
{
"value": "en",
@@ -119,12 +115,9 @@
</form>
</div>
{{#js}}
require(['core/yui'], function(Y) {
Y.use('moodle-core-formautosubmit', function() {
M.core.init_formautosubmit({
selectid: '{{id}}',
nothing: {{#hasnothing}}'{{nothingkey}}'{{/hasnothing}}{{^hasnothing}}false{{/hasnothing}}
});
require(['jquery'], function($) {
$('#{{id}}').change(function() {
$('#{{formid}}').submit();
});
});
{{/js}}
@@ -37,12 +37,9 @@
</div>
{{^showbutton}}
{{#js}}
require(['core/yui'], function(Y) {
Y.use('moodle-core-formautosubmit', function() {
M.core.init_formautosubmit({
selectid: '{{id}}',
nothing: {{#hasnothing}}'{{nothingkey}}'{{/hasnothing}}{{^hasnothing}}false{{/hasnothing}}
});
require(['jquery'], function($) {
$('#{{id}}').change(function() {
$('#{{formid}}').submit();
});
});
{{/js}}

0 comments on commit 588b84f

Please sign in to comment.