Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-25937 Forms Library: Filepicker will respect disable if

  • Loading branch information...
commit 63d5c4ac8577f75b9e82a684587597bec6affa5a 1 parent c6aa367
Rajesh Taneja authored
View
19 lib/form/filepicker.js
@@ -1,19 +1,34 @@
M.form_filepicker = {};
-
+M.form_filepicker.Y = null;
+M.form_filepicker.instances = [];
M.form_filepicker.callback = function(params) {
var html = '<a href="'+params['url']+'">'+params['file']+'</a>';
document.getElementById('file_info_'+params['client_id']).innerHTML = html;
+ //When file is added then set status of global variable to true
+ var elementname = M.core_filepicker.instances[params['client_id']].options.elementname;
+ M.form_filepicker.instances[elementname].fileadded = true;
+ //generate event to indicate changes which will be used by disable if or validation code
+ M.form_filepicker.Y.one('#id_'+elementname).simulate('change');
};
/**
* This fucntion is called for each file picker on page.
*/
M.form_filepicker.init = function(Y, options) {
+ //Keep reference of YUI, so that it can be used in callback.
+ M.form_filepicker.Y = Y;
+
+ //For client side validation, initialize file status for this filepicker
+ M.form_filepicker.instances[options.elementname] = {};
+ M.form_filepicker.instances[options.elementname].fileadded = false;
+
+ //Set filepicker callback
options.formcallback = M.form_filepicker.callback;
+
if (!M.core_filepicker.instances[options.client_id]) {
- M.core_filepicker.init(Y, options);
+ M.core_filepicker.init(Y, options);
}
Y.on('click', function(e, client_id) {
e.preventDefault();
View
3  lib/form/filepicker.php
@@ -79,6 +79,7 @@ function toHtml() {
$args->maxbytes = $this->_options['maxbytes'];
$args->context = $PAGE->context;
$args->buttonname = $elname.'choose';
+ $args->elementname = $elname;
$html = $this->_getTabs();
$fp = new file_picker($args);
@@ -87,7 +88,7 @@ function toHtml() {
$html .= $OUTPUT->render($fp);
$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'));
+ $module = array('name'=>'form_filepicker', 'fullpath'=>'/lib/form/filepicker.js', 'requires'=>array('core_filepicker', 'node', 'node-event-simulate'));
$PAGE->requires->js_init_call('M.form_filepicker.init', array($fp->options), true, $module);
$nonjsfilepicker = new moodle_url('/repository/draftfiles_manager.php', array(
View
24 lib/form/form.js
@@ -277,7 +277,17 @@ M.form.initFormDependencies = function(Y, formid, dependencies) {
} else if (this.getAttribute('type').toLowerCase() == 'checkbox' && !Y.Node.getDOMNode(this).checked) {
return;
}
- lock = lock || this.get('value') == value;
+ //check for filepicker status
+ if (this.getAttribute('class').toLowerCase() == 'filepickerhidden') {
+ var elementname = this.getAttribute('name');
+ if (elementname && M.form_filepicker.instances[elementname].fileadded) {
+ lock = false;
+ } else {
+ lock = true;
+ }
+ } else {
+ lock = lock || this.get('value') == value;
+ }
});
return {
lock : lock,
@@ -298,7 +308,17 @@ M.form.initFormDependencies = function(Y, formid, dependencies) {
} else if (this.getAttribute('type').toLowerCase() == 'checkbox' && !Y.Node.getDOMNode(this).checked) {
return;
}
- lock = lock || this.get('value') != value;
+ //check for filepicker status
+ if (this.getAttribute('class').toLowerCase() == 'filepickerhidden') {
+ var elementname = this.getAttribute('name');
+ if (elementname && M.form_filepicker.instances[elementname].fileadded) {
+ lock = true;
+ } else {
+ lock = false;
+ }
+ } else {
+ lock = lock || this.get('value') != value;
+ }
});
return {
lock : lock,
View
2  lib/formslib.php
@@ -2347,7 +2347,7 @@ function finishForm(&$form){
if (!$form->isFrozen()) {
$args = $form->getLockOptionObject();
if (count($args[1]) > 0) {
- $PAGE->requires->js_init_call('M.form.initFormDependencies', $args, false, moodleform::get_js_module());
+ $PAGE->requires->js_init_call('M.form.initFormDependencies', $args, true, moodleform::get_js_module());
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.