Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-25937 Forms Library: Added Javascript validation for filepicker a…

…nd filemanager. Also fixed disbledif rule check for both
  • Loading branch information...
commit 312a8e04362a56249d75037c3c1ac559cb000b75 1 parent 59bc05c
Rajesh Taneja authored
View
10 lib/form/filemanager.js
@@ -53,6 +53,9 @@ M.form_filemanager.init = function(Y, options) {
api: M.cfg.wwwroot+'/repository/draftfiles_ajax.php',
menus: {},
initializer: function(options) {
+ //For client side validation, remove hidden draft_id
+ Y.one('#id_'+options.elementname).set('value', '');
+
this.options = options;
if (options.mainfile) {
this.enablemainfile = options.mainfile;
@@ -69,6 +72,7 @@ M.form_filemanager.init = function(Y, options) {
this.filepicker_options.maxbytes = this.maxbytes;
this.filepicker_options.env = 'filemanager';
this.filepicker_options.itemid = options.itemid;
+ this.filepicker_options.elementname = options.elementname;
if (options.filecount) {
this.filecount = options.filecount;
@@ -150,6 +154,12 @@ M.form_filemanager.init = function(Y, options) {
button_addfile.setStyle('display', 'none');
}
this.refresh(this.currentpath);
+ //When file is added then set draftid for validation
+ var elementname = M.core_filepicker.instances[this.client_id].options.elementname;
+ var itemid = M.core_filepicker.instances[this.client_id].options.itemid;
+ Y.one('#id_'+elementname).set('value', itemid);
+ //generate event to indicate changes which will be used by disable if code.
+ Y.one('#id_'+elementname).simulate('change');
},
refresh: function(filepath) {
var scope = this;
View
8 lib/form/filemanager.php
@@ -147,14 +147,12 @@ function toHtml() {
$options->accepted_types = $accepted_types;
$options->return_types = FILE_INTERNAL;
$options->context = $PAGE->context;
+ $options->elementname = $elname;
$html = $this->_getTabs();
$html .= form_filemanager_render($options);
- $html .= '<input value="'.$draftitemid.'" name="'.$elname.'" type="hidden" />';
- // label element needs 'for' attribute work
- $html .= '<input value="" id="id_'.$elname.'" type="hidden" />';
-
+ $html .= '<input id="id_'.$elname.'" value="'.$draftitemid.'" name="'.$elname.'" type="hidden" class="filemanagerhidden"/>';
return $html;
}
}
@@ -304,7 +302,7 @@ function form_filemanager_render($options) {
$module = array(
'name'=>'form_filemanager',
'fullpath'=>'/lib/form/filemanager.js',
- 'requires' => array('core_filepicker', 'base', 'io', 'node', 'json', 'yui2-button', 'yui2-container', 'yui2-layout', 'yui2-menu', 'yui2-treeview'),
+ 'requires' => array('core_filepicker', 'base', 'io-base', 'node', 'node-event-simulate', 'json', 'yui2-button', 'yui2-container', 'yui2-layout', 'yui2-menu', 'yui2-treeview'),
'strings' => array(array('loading', 'repository'), array('nomorefiles', 'repository'), array('confirmdeletefile', 'repository'),
array('add', 'repository'), array('accessiblefilepicker', 'repository'), array('move', 'moodle'),
array('cancel', 'moodle'), array('download', 'moodle'), array('ok', 'moodle'),
View
9 lib/form/filepicker.js
@@ -5,12 +5,21 @@ M.form_filepicker = {};
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 draftid for validation
+ var elementname = M.core_filepicker.instances[params['client_id']].options.elementname;
+ var itemid = M.core_filepicker.instances[params['client_id']].options.itemid;
+ M.form_filepicker.YUI.one('#id_'+elementname).set('value', itemid);
+ //generate event to indicate changes which will be used by disable if code.
+ M.form_filepicker.YUI.one('#id_'+elementname).simulate('change');
};
/**
* This fucntion is called for each file picker on page.
*/
M.form_filepicker.init = function(Y, options) {
+ //For client side validation, remove hidden draft_id
+ M.form_filepicker.YUI = Y;
+ Y.one('#id_'+options.elementname).set('value', '');
options.formcallback = M.form_filepicker.callback;
if (!M.core_filepicker.instances[options.client_id]) {
M.core_filepicker.init(Y, options);
View
4 lib/form/filepicker.php
@@ -79,15 +79,17 @@ 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);
$options = $fp->options;
$options->context = $PAGE->context;
+ $fp->options->elementname = $elname;
$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
6 lib/formslib.php
@@ -332,7 +332,7 @@ function _validate_files(&$files) {
*
* @return bool/array with errors
*/
- function _validate_draft_files() {
+ protected function validate_draft_files() {
global $USER;
$mform =& $this->_form;
@@ -465,7 +465,7 @@ function validate_defined_fields($validateonnosubmit=false) {
$file_val = $this->_validate_files($files);
//check draft files for validation and flag them if required files
//are not in draft area.
- $draftfilevalue = $this->_validate_draft_files();
+ $draftfilevalue = $this->validate_draft_files();
if ($file_val !== true && $draftfilevalue !== true) {
$file_val = array_merge($file_val, $draftfilevalue);
@@ -2327,7 +2327,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.