mirror of
https://github.com/moodle/moodle.git
synced 2025-08-09 10:56:56 +02:00
Merge branch 'MDL-52318-35' of https://github.com/snake/moodle into MOODLE_35_STABLE
This commit is contained in:
commit
e3796a0678
3 changed files with 33 additions and 2 deletions
|
@ -12,5 +12,8 @@ M.form_url.init = function(Y, options) {
|
||||||
};
|
};
|
||||||
|
|
||||||
M.form_url.callback = function (params) {
|
M.form_url.callback = function (params) {
|
||||||
document.getElementById('id_externalurl').value = params.url;
|
// Get the first child of type 'input' within the wrapper div associated with the filepicker's id.
|
||||||
|
var urlElement = document.getElementById('url-wrapper-' + params.client_id).getElementsByTagName('input')[0];
|
||||||
|
urlElement.value = params.url;
|
||||||
|
urlElement.focus();
|
||||||
};
|
};
|
||||||
|
|
|
@ -48,6 +48,9 @@ class MoodleQuickForm_url extends HTML_QuickForm_text implements templatable {
|
||||||
/** @var bool if true label will be hidden */
|
/** @var bool if true label will be hidden */
|
||||||
var $_hiddenLabel=false;
|
var $_hiddenLabel=false;
|
||||||
|
|
||||||
|
/** @var string the unique id of the filepicker, if enabled.*/
|
||||||
|
protected $filepickeruniqueid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
|
@ -122,6 +125,7 @@ class MoodleQuickForm_url extends HTML_QuickForm_text implements templatable {
|
||||||
|
|
||||||
// Print out file picker.
|
// Print out file picker.
|
||||||
$str .= $this->getFilePickerHTML();
|
$str .= $this->getFilePickerHTML();
|
||||||
|
$str = '<div id="url-wrapper-' . $this->get_filepicker_unique_id() . '">' . $str . '</div>';
|
||||||
|
|
||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
@ -130,7 +134,7 @@ class MoodleQuickForm_url extends HTML_QuickForm_text implements templatable {
|
||||||
global $PAGE, $OUTPUT;
|
global $PAGE, $OUTPUT;
|
||||||
|
|
||||||
$str = '';
|
$str = '';
|
||||||
$clientid = uniqid();
|
$clientid = $this->get_filepicker_unique_id();
|
||||||
|
|
||||||
$args = new stdClass();
|
$args = new stdClass();
|
||||||
$args->accepted_types = '*';
|
$args->accepted_types = '*';
|
||||||
|
@ -186,6 +190,13 @@ EOD;
|
||||||
public function export_for_template(renderer_base $output) {
|
public function export_for_template(renderer_base $output) {
|
||||||
$context = $this->export_for_template_base($output);
|
$context = $this->export_for_template_base($output);
|
||||||
$context['filepickerhtml'] = !empty($this->_options['usefilepicker']) ? $this->getFilePickerHTML() : '';
|
$context['filepickerhtml'] = !empty($this->_options['usefilepicker']) ? $this->getFilePickerHTML() : '';
|
||||||
|
|
||||||
|
// This will conditionally wrap the element in a div which can be accessed in the DOM using the unique id,
|
||||||
|
// and allows the filepicker callback to find its respective url field, if multiple URLs are used.
|
||||||
|
if ($this->_options['usefilepicker']) {
|
||||||
|
$context['filepickerclientid'] = $this->get_filepicker_unique_id();
|
||||||
|
}
|
||||||
|
|
||||||
return $context;
|
return $context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,4 +209,15 @@ EOD;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the unique id of the file picker associated with this url element, setting it in the process if not set.
|
||||||
|
*
|
||||||
|
* @return string the unique id of the file picker.
|
||||||
|
*/
|
||||||
|
protected function get_filepicker_unique_id() : string {
|
||||||
|
if (empty($this->filepickeruniqueid)) {
|
||||||
|
$this->filepickeruniqueid = uniqid();
|
||||||
|
}
|
||||||
|
return $this->filepickeruniqueid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
{{< core_form/element-template }}
|
{{< core_form/element-template }}
|
||||||
{{$element}}
|
{{$element}}
|
||||||
|
{{#element.filepickerclientid}}
|
||||||
|
<div id="url-wrapper-{{element.filepickerclientid}}" class="d-inline-block">
|
||||||
|
{{/element.filepickerclientid}}
|
||||||
<input type="url"
|
<input type="url"
|
||||||
class="form-control {{#error}}is-invalid{{/error}}"
|
class="form-control {{#error}}is-invalid{{/error}}"
|
||||||
name="{{element.name}}"
|
name="{{element.name}}"
|
||||||
|
@ -13,6 +16,9 @@
|
||||||
readonly {{#element.hardfrozen}}disabled{{/element.hardfrozen}}
|
readonly {{#element.hardfrozen}}disabled{{/element.hardfrozen}}
|
||||||
{{/element.frozen}}
|
{{/element.frozen}}
|
||||||
{{{element.attributes}}} >
|
{{{element.attributes}}} >
|
||||||
|
{{#element.filepickerclientid}}
|
||||||
|
</div>
|
||||||
|
{{/element.filepickerclientid}}
|
||||||
{{^element.frozen}}
|
{{^element.frozen}}
|
||||||
{{{element.filepickerhtml}}}
|
{{{element.filepickerhtml}}}
|
||||||
{{/element.frozen}}
|
{{/element.frozen}}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue