MDL-70760 admin: Limited length config setting validate client-side
This commit is contained in:
+33
-1
@@ -2447,6 +2447,8 @@ class admin_setting_configtext extends admin_setting {
|
||||
|
||||
/** @var int default field size */
|
||||
public $size;
|
||||
/** @var array List of arbitrary data attributes */
|
||||
protected $datavalues = [];
|
||||
|
||||
/**
|
||||
* Config text constructor
|
||||
@@ -2530,11 +2532,24 @@ class admin_setting_configtext extends admin_setting {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set arbitrary data attributes for template.
|
||||
*
|
||||
* @param string $key Attribute key for template.
|
||||
* @param string $value Attribute value for template.
|
||||
*/
|
||||
public function set_data_attribute(string $key, string $value): void {
|
||||
$this->datavalues[] = [
|
||||
'key' => $key,
|
||||
'value' => $value,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an XHTML string for the setting
|
||||
* @return string Returns an XHTML string
|
||||
*/
|
||||
public function output_html($data, $query='') {
|
||||
public function output_html($data, $query = '') {
|
||||
global $OUTPUT;
|
||||
|
||||
$default = $this->get_defaultsetting();
|
||||
@@ -2545,6 +2560,8 @@ class admin_setting_configtext extends admin_setting {
|
||||
'value' => $data,
|
||||
'forceltr' => $this->get_force_ltr(),
|
||||
'readonly' => $this->is_readonly(),
|
||||
'data' => $this->datavalues,
|
||||
'maxcharacter' => array_key_exists('validation-max-length', $this->datavalues),
|
||||
];
|
||||
$element = $OUTPUT->render_from_template('core_admin/setting_configtext', $context);
|
||||
|
||||
@@ -2578,6 +2595,7 @@ class admin_setting_configtext_with_maxlength extends admin_setting_configtext {
|
||||
public function __construct($name, $visiblename, $description, $defaultsetting, $paramtype=PARAM_RAW,
|
||||
$size=null, $maxlength = 0) {
|
||||
$this->maxlength = $maxlength;
|
||||
$this->set_data_attribute('validation-max-length', $maxlength);
|
||||
parent::__construct($name, $visiblename, $description, $defaultsetting, $paramtype, $size);
|
||||
}
|
||||
|
||||
@@ -2604,6 +2622,20 @@ class admin_setting_configtext_with_maxlength extends admin_setting_configtext {
|
||||
return $parentvalidation;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an XHTML string for the setting.
|
||||
*
|
||||
* @param string $data data.
|
||||
* @param string $query query statement.
|
||||
* @return string Returns an XHTML string
|
||||
*/
|
||||
public function output_html($data, $query = ''): string {
|
||||
global $PAGE;
|
||||
$PAGE->requires->js_call_amd('core_form/configtext_maxlength', 'init');
|
||||
|
||||
return parent::output_html($data, $query);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user