PDA

View Full Version : category dropdown in header search box



Nazzal
May 19, 2020, 10:00 PM
Hello,

Any idea how to make the dropdown categories box to be closed when choosing the last subcategory?
3717

Thanks

Viktor
May 20, 2020, 04:07 AM
Open the file: ftp://templates>>your_template>>js>>lib.js
find the code:


// load data before action
base.query = $.getJSON(rlConfig['ajax_url'], {
mode: 'getCategoriesByType',
type: !jQuery.isNumeric(id) ? id : base.type_key,
id: id,
lang: rlLang
}, function(response){
if (response == null || response.length == 0)
return;

if (typeof base.data[base.type_key] == 'undefined') {
base.data[base.type_key] = new Array();
}

base.data[base.type_key][id] = new Array();

for (var i = 0; i < response.length; i++) {
base.data[base.type_key][id].push(response[i]);
}
base.buildDropdown(id);
});


and replace to:



base.query = $.getJSON(rlConfig['ajax_url'], {
mode: 'getCategoriesByType',
type: !jQuery.isNumeric(id) ? id : base.type_key,
id: id,
lang: rlLang
}, function(response){
if (response == null || response.length == 0) {
setTimeout(function(){
base.container.parent().removeClass('opened');
}, 200);
return;
}

if (typeof base.data[base.type_key] == 'undefined') {
base.data[base.type_key] = new Array();
}

base.data[base.type_key][id] = new Array();

for (var i = 0; i < response.length; i++) {
base.data[base.type_key][id].push(response[i]);
}
base.buildDropdown(id);
});


then below find:


base.defaultSelection = function(id){
if (parseInt(base.opts.default_selection) > 0) {
// load data before action
if (id == 0) {
$.getJSON(rlConfig['ajax_url'], {
item: 'getCategoriesByType',
type: base.type_key,
id: base.opts.default_selection,
lang: rlLang
}, function(response){
if (response != null && response.length > 0) {
base.parents = response.split(',').reverse();
}
base.triggerSelection();
});
}
// continue selection
else {
base.triggerSelection();
}
}
}


and replace to:


base.defaultSelection = function(id){
if (parseInt(base.opts.default_selection) > 0) {
// load data before action
if (id == 0) {
$.getJSON(rlConfig['ajax_url'], {
item: 'getCategoriesByType',
type: base.type_key,
id: base.opts.default_selection,
lang: rlLang
}, function(response){
if (response != null && response.length > 0) {
base.parents = response.split(',').reverse();
} else {
setTimeout(function(){
base.container.parent().removeClass('opened');
}, 200);
}
base.triggerSelection();
});
}
// continue selection
else {
base.triggerSelection();
}
}
}


save and check again.

kiowa
May 20, 2020, 05:32 AM
Tanks for this. Was wondering how to do this, specialy for mobile.

Viktor
May 20, 2020, 08:08 AM
Yes you can add a condition for mobile only:



base.query = $.getJSON(rlConfig['ajax_url'], {
mode: 'getCategoriesByType',
type: !jQuery.isNumeric(id) ? id : base.type_key,
id: id,
lang: rlLang
}, function(response){
if (response == null || response.length == 0) {
if (media_query == 'mobile') {
setTimeout(function(){
base.container.parent().removeClass('opened');
}, 200);
}
return;
}

if (typeof base.data[base.type_key] == 'undefined') {
base.data[base.type_key] = new Array();
}

base.data[base.type_key][id] = new Array();

for (var i = 0; i < response.length; i++) {
base.data[base.type_key][id].push(response[i]);
}
base.buildDropdown(id);
});


and



base.defaultSelection = function(id){
if (parseInt(base.opts.default_selection) > 0) {
// load data before action
if (id == 0) {
$.getJSON(rlConfig['ajax_url'], {
item: 'getCategoriesByType',
type: base.type_key,
id: base.opts.default_selection,
lang: rlLang
}, function(response){
if (response != null && response.length > 0) {
base.parents = response.split(',').reverse();
} else {
if (media_query == 'mobile') {
setTimeout(function(){
base.container.parent().removeClass('opened');
}, 200);
}
}
base.triggerSelection();
});
}
// continue selection
else {
base.triggerSelection();
}
}
}

Nazzal
May 20, 2020, 05:05 PM
Thank you Viktor, how to make it for both mobile and web view?

Viktor
May 21, 2020, 04:01 AM
Thank you Viktor, how to make it for both mobile and web view?

Use my 1st post :) in the 2nd post I added condition for mobile.

Nazzal
May 22, 2020, 08:52 PM
Hello Viktor,

Unfortunately its not working :/

Viktor
May 24, 2020, 10:38 AM
I suggest you create a new ticket with the request. Because it is working on my local site.

Nazzal
November 2, 2020, 05:50 PM
Hello Viktor,

After updating to the V4.8.1 its no longer work, please advice if there is any further modification to this code?

Nazzal
November 19, 2020, 04:53 PM
Hello Rudi,

Can you help on this please? it was working before!

Rudi
November 19, 2020, 05:39 PM
Hello,

You need to create a ticket with this issue and we'll check it

Rudi
November 20, 2020, 03:07 PM
For those who have problems after updating to 4.8.1

replace:


base.container.parent().removeClass('opened');


with:


base.container.removeClass('opened');