Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-26167 lib/form: Altering Javascript so that "disabledIf" will dis…

…able the "Choose" button for a filepicker
  • Loading branch information...
commit 9b482d1cbec3b6ac7980f30113ae9d669f67ca9b 1 parent 50467e5
@agwells agwells authored
View
3  lib/form/filepicker.php
@@ -77,13 +77,14 @@ function toHtml() {
$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 .= '<input type="hidden" name="'.$elname.'" id="'.$id.'" value="'.$draftitemid.'" />';
+ $html .= '<input type="hidden" name="'.$elname.'" id="'.$id.'" value="'.$draftitemid.'" class="filepickerhidden"/>';
$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);
View
13 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');
+ }
+ });
+ }
})
},
/**
View
1  lib/outputcomponents.php
@@ -57,6 +57,7 @@ public function __construct(stdClass $options) {
'itemid' => 0,
'maxbytes'=>-1,
'maxfiles'=>1,
+ 'buttonname'=>false,
);
foreach ($defaults as $key=>$value) {
if (empty($options->$key)) {
View
7 lib/outputrenderers.php
@@ -1979,13 +1979,18 @@ public function render_file_picker(file_picker $fp) {
} else {
$maxsize = get_string('maxfilesize', 'moodle', display_size($size));
}
+ if ($options->buttonname){
+ $buttonname = ' name="' . $options->buttonname . '"';
+ } else {
+ $buttonname = '';
+ }
$html = <<<EOD
<div class="filemanager-loading mdl-align" id='filepicker-loading-{$client_id}'>
$icon_progress
</div>
<div id="filepicker-wrapper-{$client_id}" class="mdl-left" style="display:none">
<div>
- <input type="button" id="filepicker-button-{$client_id}" value="{$straddfile}" />
+ <input type="button" id="filepicker-button-{$client_id}" value="{$straddfile}"{$buttonname}/>
<span> $maxsize </span>
</div>
EOD;
Please sign in to comment.
Something went wrong with that request. Please try again.