Merge branch 'MDL-63685-master' of git://github.com/marinaglancy/moodle

This commit is contained in:
Andrew Nicols 2019-05-06 08:41:20 +08:00
commit 454c18c380
3 changed files with 50 additions and 13 deletions

View File

@ -61,7 +61,8 @@ class MoodleQuickForm_cancel extends MoodleQuickForm_submit
$value=get_string('cancel');
}
parent::__construct($elementName, $value, $attributes);
$this->updateAttributes(array('onclick'=>'skipClientValidation = true; return true;'));
$this->updateAttributes(array('data-skip-validation' => 1, 'data-cancel' => 1,
'onclick' => 'skipClientValidation = true; return true;'));
// Add the class btn-cancel.
$class = $this->getAttribute('class');
@ -93,7 +94,7 @@ class MoodleQuickForm_cancel extends MoodleQuickForm_submit
{
switch ($event) {
case 'createElement':
static::__construct($arg[0], $arg[1], $arg[2]);
parent::onQuickFormEvent($event, $arg, $caller);
$caller->_registerCancelButton($this->getName());
return true;
break;

View File

@ -112,7 +112,7 @@ class MoodleQuickForm_submit extends HTML_QuickForm_submit implements templatabl
$onClick = $this->getAttribute('onclick');
$skip = 'skipClientValidation = true;';
$onClick = ($onClick !== null)?$skip.' '.$onClick:$skip;
$this->updateAttributes(array('onclick'=>$onClick));
$this->updateAttributes(array('data-skip-validation' => 1, 'data-no-submit' => 1, 'onclick' => $onClick));
}
return true;
break;

View File

@ -198,7 +198,7 @@ abstract class moodleform {
$this->_formname = $this->get_form_identifier();
$this->_ajaxformdata = $ajaxformdata;
$this->_form = new MoodleQuickForm($this->_formname, $method, $action, $target, $attributes);
$this->_form = new MoodleQuickForm($this->_formname, $method, $action, $target, $attributes, $ajaxformdata);
if (!$editable){
$this->_form->hardFreeze();
}
@ -503,7 +503,7 @@ abstract class moodleform {
return false;
}
foreach ($mform->_noSubmitButtons as $nosubmitbutton){
if (optional_param($nosubmitbutton, 0, PARAM_RAW)){
if ($this->optional_param($nosubmitbutton, 0, PARAM_RAW)) {
$nosubmit = true;
break;
}
@ -511,6 +511,21 @@ abstract class moodleform {
return $nosubmit;
}
/**
* Checks if a parameter was passed in the previous form submission
*
* @param string $name the name of the page parameter we want
* @param mixed $default the default value to return if nothing is found
* @param string $type expected type of parameter
* @return mixed
*/
public function optional_param($name, $default, $type) {
if (isset($this->_ajaxformdata[$name])) {
return clean_param($this->_ajaxformdata[$name], $type);
} else {
return optional_param($name, $default, $type);
}
}
/**
* Check that form data is valid.
@ -616,7 +631,7 @@ abstract class moodleform {
$mform =& $this->_form;
if ($mform->isSubmitted()){
foreach ($mform->_cancelButtons as $cancelbutton){
if (optional_param($cancelbutton, 0, PARAM_RAW)){
if ($this->optional_param($cancelbutton, 0, PARAM_RAW)) {
return true;
}
}
@ -1085,8 +1100,8 @@ abstract class moodleform {
} else {
$addstring = str_ireplace('{no}', $addfieldsno, $addstring);
}
$repeats = optional_param($repeathiddenname, $repeats, PARAM_INT);
$addfields = optional_param($addfieldsname, '', PARAM_TEXT);
$repeats = $this->optional_param($repeathiddenname, $repeats, PARAM_INT);
$addfields = $this->optional_param($addfieldsname, '', PARAM_TEXT);
if (!empty($addfields)){
$repeats += $addfieldsno;
}
@ -1205,8 +1220,8 @@ abstract class moodleform {
}
$mform = $this->_form;
$selectvalue = optional_param($checkboxcontrollerparam, null, PARAM_INT);
$contollerbutton = optional_param($checkboxcontrollername, null, PARAM_ALPHAEXT);
$selectvalue = $this->optional_param($checkboxcontrollerparam, null, PARAM_INT);
$contollerbutton = $this->optional_param($checkboxcontrollername, null, PARAM_ALPHAEXT);
$newselectvalue = $selectvalue;
if (is_null($selectvalue)) {
@ -1502,6 +1517,9 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
*/
var $_pageparams = '';
/** @var array $_ajaxformdata submitted form data when using mforms with ajax */
protected $_ajaxformdata;
/**
* Whether the form contains any client-side validation or not.
* @var bool
@ -1527,8 +1545,9 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
* @param string|moodle_url $action Form's action
* @param string $target (optional)Form's target defaults to none
* @param mixed $attributes (optional)Extra attributes for <form> tag
* @param array $ajaxformdata Forms submitted via ajax, must pass their data here, instead of relying on _GET and _POST.
*/
public function __construct($formName, $method, $action, $target='', $attributes=null) {
public function __construct($formName, $method, $action, $target = '', $attributes = null, $ajaxformdata = null) {
global $CFG, $OUTPUT;
static $formcounter = 1;
@ -1553,6 +1572,7 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
$this->updateAttributes($attributes);
// This is custom stuff for Moodle :
$this->_ajaxformdata = $ajaxformdata;
$oldclass= $this->getAttribute('class');
if (!empty($oldclass)){
$this->updateAttributes(array('class'=>$oldclass.' mform'));
@ -1592,6 +1612,22 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
}
}
/**
* Checks if a parameter was passed in the previous form submission
*
* @param string $name the name of the page parameter we want
* @param mixed $default the default value to return if nothing is found
* @param string $type expected type of parameter
* @return mixed
*/
public function optional_param($name, $default, $type) {
if (isset($this->_ajaxformdata[$name])) {
return clean_param($this->_ajaxformdata[$name], $type);
} else {
return optional_param($name, $default, $type);
}
}
/**
* Use this method to indicate that the fieldset should be shown as expanded.
* The method is applicable to header elements only.
@ -1617,7 +1653,7 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
}
if ($this->getElementType('mform_isexpanded_' . $headerid) === false) {
// See if the form has been submitted already.
$formexpanded = optional_param('mform_isexpanded_' . $headerid, -1, PARAM_INT);
$formexpanded = $this->optional_param('mform_isexpanded_' . $headerid, -1, PARAM_INT);
if (!$ignoreuserstate && $formexpanded != -1) {
// Override expanded state with the form variable.
$expanded = $formexpanded;
@ -1641,7 +1677,7 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
// Add extra hidden element to store advanced items state for each section.
if ($this->getElementType('mform_showmore_' . $headerid) === false) {
// See if we the form has been submitted already.
$formshowmore = optional_param('mform_showmore_' . $headerid, -1, PARAM_INT);
$formshowmore = $this->optional_param('mform_showmore_' . $headerid, -1, PARAM_INT);
if (!$showmore && $formshowmore != -1) {
// Override showmore state with the form variable.
$showmore = $formshowmore;