Close

Modify javascript to catch when user click a spec filter

winebear
9 years ago
#9236 Quote
Avatar
  • 37
We would like to hook in to the javascript for when someone clicks on a filter, to trigger some javascript that is run BEFORE the filtering takes place.
The reason for this is that when a user clicks some specific filters, we want to automatically click other filters.
Can you clarify the best way of achieving this?
iliyan.tanev
9 years ago
#9244 Quote
Avatar
  • 347
Hi,

This could cause an error if you select several more filter options when specific one is selected, because the other options can be disabled after specific filtration.
For example if you have this filter group:

Option A
Option B
Option C

After you click option A you may want to select Option B as well, but Option B may be unavailable after filtration which will cause error.

This is why we do not provide a way to do this.
Regards,
Iliyan Tanev
Nop-Templates Dev Team
winebear
9 years ago
#9246 Quote
Avatar
  • 37
Surely I just need to check that the item is not disabled before ticking it though?
winebear
9 years ago
#9247 Quote
Avatar
  • 37
To clarify, I want to tick options within the same group. Ticking one option from a group will not disable other items from the same group, so I cannot see why there would be a problem.
iliyan.tanev
9 years ago
#9248 Quote
Avatar
  • 347
winebear wrote:
Surely I just need to check that the item is not disabled before ticking it though?


Actually you could not do this before the filtering is done, because the available filters are returned by the server.

winebear wrote:
To clarify, I want to tick options within the same group. Ticking one option from a group will not disable other items from the same group, so I cannot see why there would be a problem.


You are right. It was a bad example. And when you need to do it only for one filter group at a time, it is ok.
You will need to add a click event to every anchor element in your filter group and in the handler change the filterItemUnselected class to filterItemSelected, for every other filter option you want to select.
Regards,
Iliyan Tanev
Nop-Templates Dev Team
winebear
9 years ago
#9249 Quote
Avatar
  • 37
Thank you Iliyan
winebear
9 years ago
#9251 Quote
Avatar
  • 37
This is not working.
Whilst the code I have added sets the item to appear selected momentarily, it then deselects itself straight afterwards. I assume there is something in your javascript that checks the links once the ajax call has been made, and corrects any that are incorrect.
Can you take a look and let me know?
iliyan.tanev
9 years ago
#9252 Quote
Avatar
  • 347
Hi,

Probably your implementation changes the class after the filtration is complete. This will cause the changed classes to be corrected by the Filter JavaScript. 
Regards,
Iliyan Tanev
Nop-Templates Dev Team
winebear
9 years ago
#9253 Quote
Avatar
  • 37
Yes, hence my ORIGINAL question "to trigger some javascript that is run BEFORE the filtering takes place"
iliyan.tanev
9 years ago
#9254 Quote
Avatar
  • 347
Hi,

We are not sure if this is possible without the Filters JavaScript. Could you submit a ticket about this and we will continue the conversation there. 
Regards,
Iliyan Tanev
Nop-Templates Dev Team