MDL-83883 datafilter: Fix initial state of binary filter

When a filter is added to a page after the initial page load, no
initialValues are passed, so we need to set a default value.
This commit is contained in:
Mark Johnson 2024-12-04 11:21:01 +00:00
parent a798b1db39
commit e347532af4
No known key found for this signature in database
GPG Key ID: EB30E1468CFAE242
3 changed files with 4 additions and 3 deletions

View File

@ -1,3 +1,3 @@
define("core/datafilter/filtertypes/binary",["exports","core/datafilter/filtertype","core/datafilter/selectors","core/templates","core/str"],(function(_exports,_filtertype,_selectors,_templates,_str){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_filtertype=_interopRequireDefault(_filtertype),_selectors=_interopRequireDefault(_selectors),_templates=_interopRequireDefault(_templates);class _default extends _filtertype.default{constructor(){super(...arguments),_defineProperty(this,"optionOne",void 0),_defineProperty(this,"optionTwo",void 0)}async addValueSelector(initialValues){return[this.optionOne,this.optionTwo]=await this.getTextValues(),this.displayBinarySelection(initialValues[0])}getTextValues(){return(0,_str.get_strings)([{key:"no"},{key:"yes"}])}async displayBinarySelection(){let initialValue=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;const specificFilterSet=this.rootNode.querySelector(_selectors.default.filter.byName(this.filterType)),sourceDataNode=this.getSourceDataForFilter(),context={filtertype:this.filterType,title:sourceDataNode.getAttribute("data-field-title"),required:sourceDataNode.dataset.required,options:[{text:this.optionOne,value:0,selected:0===initialValue},{text:this.optionTwo,value:1,selected:1===initialValue}]};return _templates.default.render("core/datafilter/filtertypes/binary_selector",context).then(((binaryUi,js)=>_templates.default.replaceNodeContents(specificFilterSet.querySelector(_selectors.default.filter.regions.values),binaryUi,js)))}get values(){return[parseInt(this.filterRoot.querySelector('[data-filterfield="'.concat(this.name,'"]')).value)]}}return _exports.default=_default,_exports.default}));
define("core/datafilter/filtertypes/binary",["exports","core/datafilter/filtertype","core/datafilter/selectors","core/templates","core/str"],(function(_exports,_filtertype,_selectors,_templates,_str){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_filtertype=_interopRequireDefault(_filtertype),_selectors=_interopRequireDefault(_selectors),_templates=_interopRequireDefault(_templates);class _default extends _filtertype.default{constructor(){super(...arguments),_defineProperty(this,"optionOne",void 0),_defineProperty(this,"optionTwo",void 0)}async addValueSelector(initialValues){[this.optionOne,this.optionTwo]=await this.getTextValues();const initialValue=initialValues?initialValues[0]:0;return this.displayBinarySelection(initialValue)}getTextValues(){return(0,_str.get_strings)([{key:"no"},{key:"yes"}])}async displayBinarySelection(){let initialValue=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;const specificFilterSet=this.rootNode.querySelector(_selectors.default.filter.byName(this.filterType)),sourceDataNode=this.getSourceDataForFilter(),context={filtertype:this.filterType,title:sourceDataNode.getAttribute("data-field-title"),required:sourceDataNode.dataset.required,options:[{text:this.optionOne,value:0,selected:0===initialValue},{text:this.optionTwo,value:1,selected:1===initialValue}]};return _templates.default.render("core/datafilter/filtertypes/binary_selector",context).then(((binaryUi,js)=>_templates.default.replaceNodeContents(specificFilterSet.querySelector(_selectors.default.filter.regions.values),binaryUi,js)))}get values(){return[parseInt(this.filterRoot.querySelector('[data-filterfield="'.concat(this.name,'"]')).value)]}}return _exports.default=_default,_exports.default}));
//# sourceMappingURL=binary.min.js.map

File diff suppressed because one or more lines are too long

View File

@ -53,7 +53,8 @@ export default class extends Filter {
*/
async addValueSelector(initialValues) {
[this.optionOne, this.optionTwo] = await this.getTextValues();
return this.displayBinarySelection(initialValues[0]);
const initialValue = initialValues ? initialValues[0] : 0;
return this.displayBinarySelection(initialValue);
}
/**