MDL-84529 core: Remove max validation on datetime filter.

This removes the "max" attribute from the input field of the
datetime filter. This can then be added back in by specific
filters if they inherit the core one and add their own
getContext() method.
This commit is contained in:
Conn Warwicker
2025-02-27 13:42:23 +00:00
parent 7a318d5c85
commit a6e30bbc04
7 changed files with 29 additions and 12 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+8 -1
View File
@@ -191,7 +191,14 @@ export default class {
// Instantiate the Filter class.
let Filter = GenericFilter;
if (filterDataNode.dataset.filterTypeClass) {
Filter = await import(filterDataNode.dataset.filterTypeClass);
// Ensure the filter class passed through exists, otherwise the filtering will break.
try {
Filter = await import(filterDataNode.dataset.filterTypeClass);
} catch (error) {
Notification.exception(error);
}
}
this.activeFilters[filterType] = new Filter(filterType, this.filterSet, initialFilterValues, filterOptions);
+15 -5
View File
@@ -50,9 +50,14 @@ export default class extends Filter {
this.addModeSelector(filterOptions.mode);
}
async addValueSelector(initialValues = []) {
// We specify a specific filterset in case there are multiple filtering condition - avoiding glitches.
const specificFilterSet = this.rootNode.querySelector(Selectors.filter.byName(this.filterType));
/**
* Get the context object to be sent through to the mustache template.
* This can be overridden by any filters which inherit from datetime to add/exclude data.
*
* @param {array} initialValues
* @returns {Promise<{filtertype: *, afterlabel: *, beforelabel: *, required, aftervalue: *, beforevalue: *}>}
*/
async getContext(initialValues) {
const sourceDataNode = this.getSourceDataForFilter();
const defaultBefore = sourceDataNode.getElementsByTagName('option')[0].value;
const defaultAfter = sourceDataNode.getElementsByTagName('option')[1].value;
@@ -69,15 +74,20 @@ export default class extends Filter {
param: {title},
},
]);
const context = {
return {
filtertype: this.filterType,
afterlabel: labels[0],
beforelabel: labels[1],
required: sourceDataNode.dataset.required,
aftervalue: initialValues[0] ?? defaultAfter,
beforevalue: initialValues[1] ?? defaultBefore,
now: defaultBefore,
};
}
async addValueSelector(initialValues = []) {
// We specify a specific filterset in case there are multiple filtering condition - avoiding glitches.
const specificFilterSet = this.rootNode.querySelector(Selectors.filter.byName(this.filterType));
const context = await this.getContext(initialValues);
const datetimeUi = await Templates.renderForPromise('core/datafilter/filtertypes/datetime_selector', context);
return Templates.replaceNodeContents(
specificFilterSet.querySelector(Selectors.filter.regions.values),
@@ -50,7 +50,7 @@
value="{{aftervalue}}"
data-filterfield="{{filtertype}}1"
data-field-title="{{afterlabel}}"
max="{{now}}"
{{#max}}max="{{max}}"{{/max}}
>
</span>
<span class="{{filtertype}}-betweenwrapper ms-2 me-2">
@@ -66,7 +66,7 @@
value="{{beforevalue}}"
data-filterfield="{{filtertype}}2"
data-field-title="{{beforelabel}}"
max="{{now}}"
{{#max}}max="{{max}}"{{/max}}
>
</span>
</div>