Skip to content

Commit

Permalink
fix: filter key for select components
Browse files Browse the repository at this point in the history
  • Loading branch information
Soare-Robert-Daniel committed Mar 4, 2024
1 parent fa82512 commit 6b11b81
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 30 deletions.
64 changes: 34 additions & 30 deletions includes/views/js/chosen.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ This file is generated by `grunt build`, do not edit it by hand.

return SelectParser;

})();
}());

SelectParser.select_to_array = function(select) {
var child, i, len, parser, ref;
Expand Down Expand Up @@ -126,12 +126,12 @@ This file is generated by `grunt build`, do not edit it by hand.
return function(evt) {
return _this.test_active_click(evt);
};
})(this);
}(this));
this.activate_action = (function(_this) {
return function(evt) {
return _this.activate_field(evt);
};
})(this);
}(this));
this.active_field = false;
this.mouse_on_container = false;
this.results_showing = false;
Expand Down Expand Up @@ -624,7 +624,7 @@ This file is generated by `grunt build`, do not edit it by hand.

return AbstractChosen;

})();
}());

$ = jQuery;

Expand Down Expand Up @@ -715,123 +715,123 @@ This file is generated by `grunt build`, do not edit it by hand.
return function(evt) {
_this.container_mousedown(evt);
};
})(this));
}(this)));
this.container.on('touchend.chosen', (function(_this) {
return function(evt) {
_this.container_mouseup(evt);
};
})(this));
}(this)));
this.container.on('mousedown.chosen', (function(_this) {
return function(evt) {
_this.container_mousedown(evt);
};
})(this));
}(this)));
this.container.on('mouseup.chosen', (function(_this) {
return function(evt) {
_this.container_mouseup(evt);
};
})(this));
}(this)));
this.container.on('mouseenter.chosen', (function(_this) {
return function(evt) {
_this.mouse_enter(evt);
};
})(this));
}(this)));
this.container.on('mouseleave.chosen', (function(_this) {
return function(evt) {
_this.mouse_leave(evt);
};
})(this));
}(this)));
this.search_results.on('mouseup.chosen', (function(_this) {
return function(evt) {
_this.search_results_mouseup(evt);
};
})(this));
}(this)));
this.search_results.on('mouseover.chosen', (function(_this) {
return function(evt) {
_this.search_results_mouseover(evt);
};
})(this));
}(this)));
this.search_results.on('mouseout.chosen', (function(_this) {
return function(evt) {
_this.search_results_mouseout(evt);
};
})(this));
}(this)));
this.search_results.on('mousewheel.chosen DOMMouseScroll.chosen', (function(_this) {
return function(evt) {
_this.search_results_mousewheel(evt);
};
})(this));
}(this)));
this.search_results.on('touchstart.chosen', (function(_this) {
return function(evt) {
_this.search_results_touchstart(evt);
};
})(this));
}(this)));
this.search_results.on('touchmove.chosen', (function(_this) {
return function(evt) {
_this.search_results_touchmove(evt);
};
})(this));
}(this)));
this.search_results.on('touchend.chosen', (function(_this) {
return function(evt) {
_this.search_results_touchend(evt);
};
})(this));
}(this)));
this.form_field_jq.on("chosen:updated.chosen", (function(_this) {
return function(evt) {
_this.results_update_field(evt);
};
})(this));
}(this)));
this.form_field_jq.on("chosen:activate.chosen", (function(_this) {
return function(evt) {
_this.activate_field(evt);
};
})(this));
}(this)));
this.form_field_jq.on("chosen:open.chosen", (function(_this) {
return function(evt) {
_this.container_mousedown(evt);
};
})(this));
}(this)));
this.form_field_jq.on("chosen:close.chosen", (function(_this) {
return function(evt) {
_this.close_field(evt);
};
})(this));
}(this)));
this.search_field.on('blur.chosen', (function(_this) {
return function(evt) {
_this.input_blur(evt);
};
})(this));
}(this)));
this.search_field.on('keyup.chosen', (function(_this) {
return function(evt) {
_this.keyup_checker(evt);
};
})(this));
}(this)));
this.search_field.on('keydown.chosen', (function(_this) {
return function(evt) {
_this.keydown_checker(evt);
};
})(this));
}(this)));
this.search_field.on('focus.chosen', (function(_this) {
return function(evt) {
_this.input_focus(evt);
};
})(this));
}(this)));
this.search_field.on('cut.chosen', (function(_this) {
return function(evt) {
_this.clipboard_event_checker(evt);
};
})(this));
}(this)));
this.search_field.on('paste.chosen', (function(_this) {
return function(evt) {
_this.clipboard_event_checker(evt);
};
})(this));
}(this)));
if (this.is_multiple) {
return this.search_choices.on('click.chosen', (function(_this) {
return function(evt) {
_this.choices_click(evt);
};
})(this));
}(this)));
} else {
return this.container.on('click.chosen', function(evt) {
evt.preventDefault();
Expand Down Expand Up @@ -1098,7 +1098,7 @@ This file is generated by `grunt build`, do not edit it by hand.
return function(evt) {
return _this.choice_destroy_link_click(evt);
};
})(this));
}(this)));
choice.append(close_link);
}
return this.search_container.before(choice);
Expand Down Expand Up @@ -1164,6 +1164,10 @@ This file is generated by `grunt build`, do not edit it by hand.
item = this.results_data[high[0].getAttribute("data-option-array-index")];
item.selected = true;
this.form_field.options[item.options_index].selected = true;

// Trigger the change event to it can be listened to.
const event = new Event('change', { bubbles: true });
this.form_field.dispatchEvent(event);
this.selected_option_count = null;
if (this.is_multiple) {
this.choice_build(item);
Expand Down Expand Up @@ -1361,6 +1365,6 @@ This file is generated by `grunt build`, do not edit it by hand.

return Chosen;

})(AbstractChosen);
}(AbstractChosen));

}).call(this);
25 changes: 25 additions & 0 deletions includes/views/js/import-metabox-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -836,4 +836,29 @@
$( '.feedzy-open-media' ).html( feedzy.i10n.action_btn_text_1 );
});
}


/**
* BUG: When a user select a value for `inc_on` or `exc_on` and then modifies the filter the keywords, the last selected value is not retained.
* Temporary FIX: Store the selected value in the session storage and then re-add it when the form is submitted.
*/
document.querySelector('[name="feedzy_meta_data[inc_on]"]').addEventListener('change', (event) => {
sessionStorage.setItem('feedzy_meta_data[inc_on]', event.target.selectedIndex);
});

document.querySelector('[name="feedzy_meta_data[exc_on]"]').addEventListener('change', (event) => {
sessionStorage.setItem('feedzy_meta_data[exc_on]', event.target.selectedIndex);
});

document.querySelector('#post').addEventListener('submit', () => {
if (sessionStorage.getItem('feedzy_meta_data[inc_on]') !== null) {
document.querySelector('[name="feedzy_meta_data[inc_on]"]').selectedIndex = sessionStorage.getItem('feedzy_meta_data[inc_on]') ?? 0;
sessionStorage.removeItem('feedzy_meta_data[inc_on]');
}

if (sessionStorage.getItem('feedzy_meta_data[exc_on]') !== null) {
document.querySelector('[name="feedzy_meta_data[exc_on]"]').selectedIndex = sessionStorage.getItem('feedzy_meta_data[exc_on]') ?? 0;
sessionStorage.removeItem('feedzy_meta_data[exc_on]');
}
});
}(jQuery, feedzy));

0 comments on commit 6b11b81

Please sign in to comment.