From 4b72f9eb78157324efaa87a2f55c27206c0eee34 Mon Sep 17 00:00:00 2001 From: Aaron Wells Date: Tue, 12 Apr 2011 14:30:13 +1200 Subject: [PATCH] MDL-26167 lib/form: Altering Javascript so that "disabledIf" will disable the "Choose" button for a filepicker --- lib/form/filepicker.php | 3 ++- lib/form/form.js | 13 +++++++++++++ lib/outputcomponents.php | 1 + lib/outputrenderers.php | 7 ++++++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/form/filepicker.php b/lib/form/filepicker.php index caa200919f0..c5af6e18866 100644 --- a/lib/form/filepicker.php +++ b/lib/form/filepicker.php @@ -77,13 +77,14 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input { $args->itemid = $draftitemid; $args->maxbytes = $this->_options['maxbytes']; $args->context = $PAGE->context; + $args->buttonname = $elname.'choose'; $html = $this->_getTabs(); $fp = new file_picker($args); $options = $fp->options; $options->context = $PAGE->context; $html .= $OUTPUT->render($fp); - $html .= ''; + $html .= ''; $module = array('name'=>'form_filepicker', 'fullpath'=>'/lib/form/filepicker.js', 'requires'=>array('core_filepicker')); $PAGE->requires->js_init_call('M.form_filepicker.init', array($fp->options), true, $module); diff --git a/lib/form/form.js b/lib/form/form.js index 42b9316ae2a..140a47502e3 100644 --- a/lib/form/form.js +++ b/lib/form/form.js @@ -198,12 +198,25 @@ M.form.initFormDependencies = function(Y, formid, dependencies) { */ _disableElement : function(name, disabled) { var els = this.elementsByName(name); + var form = this; els.each(function(){ if (disabled) { this.setAttribute('disabled', 'disabled'); } else { this.removeAttribute('disabled'); } + + // Extra code to disable a filepicker + if (this.getAttribute('class') == 'filepickerhidden'){ + var pickerbuttons = form.elementsByName(name + 'choose'); + pickerbuttons.each(function(){ + if (disabled){ + this.setAttribute('disabled','disabled'); + } else { + this.removeAttribute('disabled'); + } + }); + } }) }, /** diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index 3dfdbf77c08..7e9573c4773 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -57,6 +57,7 @@ class file_picker implements renderable { 'itemid' => 0, 'maxbytes'=>-1, 'maxfiles'=>1, + 'buttonname'=>false, ); foreach ($defaults as $key=>$value) { if (empty($options->$key)) { diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 6d89aba67e6..52c9d05a1a8 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -1979,13 +1979,18 @@ class core_renderer extends renderer_base { } else { $maxsize = get_string('maxfilesize', 'moodle', display_size($size)); } + if ($options->buttonname){ + $buttonname = ' name="' . $options->buttonname . '"'; + } else { + $buttonname = ''; + } $html = << $icon_progress