Loading...
 
Features / Usability

Features / Usability


[SOLVED] Reasons for customsearch sort impotence when search works? Bugs in tiki 25.x? e.g Uncaught TypeError: customsearch_0.load is not a function or other things?

posts: 31 Lithuania

Update1: The first trick is to use id="0" instead of id="customsearch_0"!!! Selecting sort dropdown then functions as expected.
Update2: But now the next error is because I use the different tracker fields naming:
"Field price does not exist in the current index. If this is a tracker field, the proper syntax is tracker_field_price.'
So the main question now: "What should be the correct syntax for: _options="title_asc,title_desc,price_asc,price_desc"?
And bobshopProductName_asc nor tracker_field_bobshopProductName_asc - does not work either...
Update3: Solved! The second trick is NOT to have spaces in _options!!!
_options="tracker_field_bobshopProductName_asc,tracker_field_bobshopProductName_desc,tracker_field_bobshopProductPrice_asc,tracker_field_bobshopProductPrice_desc"



Hello all!
I am into a second week struggling to make customsearch sorting to work and I can't find the reason. Either with {CUSTOMSEARCH( wiki=...
or
{CUSTOMSEARCH( tpl=...

In CustomSearchController.php

$input->sort_mode->text()

is empty all the time but I can see required changes in

$adddata = json_decode($input->adddata->text(), true);

But I can't see triggered changes when dropdown sort field is changed.
in customsearch.js and in javascript console I've got an error:

Copy to clipboard
Uncaught TypeError: customsearch_0.load is not a function at getHash (customsearch.js:281:32) at HTMLDocument.<anonymous> (customsearch.js:61:9) at HTMLDocument.dispatch (jquery.js:5430:27) at elemData.handle (jquery.js:5234:28)



One of the versions of my wiki tpl is

Copy to clipboard
{literal} ||Any text:|{input _filter="content" type="text" id="customsearch_0" class="form-control" placeholder="Search..."}|| ||Sort by:|{select id="sortby" class="sortby" _options="title_asc,title_desc,price_asc,price_desc" _labels="A-Z,Z-A,low-high,high-low "}|| ||Results per page:|{select id="max" class="max-records" _options="6,9,50" _labels="6,9,50"}|| {input type="Submit" value="Search" class="btn btn-primary"} {/literal}

(Edit: in this tpl it should be id="search", then the whole form is customsearch_customsearch0_form?)

From the documentation and extensive searches I understand that this JQ code from the example is not needed any more in tpl?

Copy to clipboard
{JQ(notonready=true)} (function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'styles/custom_search.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })(); {JQ}


Moreover, the file styles/custom_search.js doesn't exist which is referenced from "templates/examples/shop/custom_search_form.tpl" and is replaced by customsearch.js which is engaged with parameter customsearchjs="1" eg:

Copy to clipboard
{CUSTOMSEARCH( wiki="CustomSearchTPL3" id="customsearch_0" recalllastsearch="0" searchonload="1" customsearchjs="1")} {filter field="tracker_id" content="2"} {list max="9"} {sort_mode mode="title_asc"} {output template="templates/examples/shop/product_list_inner.tpl" pagination="y"} {FORMAT(name="images")}{display name="tracker_field_bobshopProductPic1" default=""}{FORMAT} {FORMAT(name="title")}{display name="tracker_field_bobshopProductName" format="trackerrender"}{FORMAT} {FORMAT(name="stock")}{display name="tracker_field_bobshopProductStockQuantity" format="trackerrender"}{FORMAT} {FORMAT(name="price")}{DIV(class="price")}{display name="tracker_field_bobshopProductPrice" format="trackerrender"}{DIV}{FORMAT} {CUSTOMSEARCH}


Also, if I put {JQ} or {HTML} portions into customsearch wiki TPL then approve plugin notice is just annoyingly stuck on the screen all the time.

Questions...
1. Is extra JQ still needed for sort to work?
2. Is that Uncaught TypeError: customsearch_0.load is not a function because of that missing JQ or is it a bug or...?
3. Do I need other things somewhere in tpl or in the rendering page?

Extra info: Search and pagination works as intended. I am not using categories.

P.S. I am trying to fuse bobshop profile and johnny's shop cart... :-)
P.P.S.

I can observe alert trigger in customsearch.js if I add a bit of extra code without $csForm parameter...

Copy to clipboard
$('#sortby').on('change', function() { alert(this.value); //this works!!! }); $("#sortby", $csForm).change(function () { alert("what the hell?? - change'); //doesn't work? customsearch_0.sort_mode = $(this).val(); // remove the representation of this select in the search delete customsearch_0.searchdata.sortby; customsearch_0.auto(); return false; });
posts: 126886 United Kingdom

Hi @Aris Bernotas

Glad you managed to work your way though this, sorry i wasn't about - sounds like we could to with a trim on the options and some better parameter description... one day mrgreen

jb


posts: 8633 Israel

Well done Aris.

Aris Bernotas wrote:
Update1: The first trick is to use id="0" instead of id="customsearch_0"!!! Selecting sort dropdown then functions as expected.


My understanding is that underscore "_" are ok for html ids. (https://stackoverflow.com/questions/70579/html-valid-id-attribute-values)

We have also an example here with underscore: https://doc.tiki.org/PluginCustomSearch#Advanced_Pagination_in_Smarty_Template

So what's the conclusion of this discussion ?
Is it ok to use underscore for a customSearch id (like Tiki sample) or it is better not to use underscore (or any special character) ?


Upcoming Events

1)  18 Apr 2024 14:00 GMT-0000
Tiki Roundtable Meeting
2)  16 May 2024 14:00 GMT-0000
Tiki Roundtable Meeting
3)  20 Jun 2024 14:00 GMT-0000
Tiki Roundtable Meeting
4)  18 Jul 2024 14:00 GMT-0000
Tiki Roundtable Meeting
5)  15 Aug 2024 14:00 GMT-0000
Tiki Roundtable Meeting
6)  19 Sep 2024 14:00 GMT-0000
Tiki Roundtable Meeting
7) 
Tiki birthday
8)  17 Oct 2024 14:00 GMT-0000
Tiki Roundtable Meeting
9)  21 Nov 2024 14:00 GMT-0000
Tiki Roundtable Meeting
10)  19 Dec 2024 14:00 GMT-0000
Tiki Roundtable Meeting