Expand my Community achievements bar.

Custom Search Predicate From 6.1 to 6.3 Not Working

Avatar

Level 3

Hello,

We are trying to transfer a custom search bar developed for 6.1 to 6.3 and after all recommended updates to the field names etc. all default predicates seem to be working but not the one custom developed. Here's the error we are facing. In 6.1 our custom JS calls Dam.Search.Util.find() from dam.admin.search.predicates. When we replicate the process in 6.3 calling the same function Dam.Search.Util.find() now part of dam.admin.search.predicates.coral we get error "Cannot read property 'go' of undefined" where undefined is var contentApi = $('.foundation-content').adaptTo('foundation-content') from /libs/dam/gui/coral/components/admin/customsearch/searchpredicates/clientlibs/searchpredicate/js/util.js.

Can someone please advise why the old library is working with 6.1 but the new one is not working with 6.3.

Any help will be greatly appreciated. 

Thanks

2 Replies

Avatar

Level 10

Are you following an online GITHub repo for code or article? It would be nice to try and duplicate what you are trying to do.

Avatar

Level 3

Hi smacdonald2008,

We have the following custom .js

========================

(function (document, $) {

    'use strict';

    $(document).ready(function () {

        var searchFormSelector = 'form.searchpanel.foundation-form',

            $formSelector = $(searchFormSelector);

        function _getId(name, el) {

            if (!name)

                name = 'predicate';

            return $(el).data('list-order') + '_' + name;

        }

        function _removeOldValues() {

            var productTextFilter = $formSelector.find("[data-type=producttext]");

            $.each(productTextFilter, function (index, el) {

                var hiddenFields = $(el).find('input[data-metatype=hidden]');

                $.each(hiddenFields, function(hIndex, hEL) {

                    $(hEL).remove();

                });

            });

        }//end function removeOldValues

        function _handleProductTextFilter() {

            var productTextFilter = $formSelector.find("[data-type=producttext]");

            var groupNumber = 1;

            $.each(productTextFilter, function(index, el) {

                var id = _getId('group', el),

                    metaProp = $(el).data('property-to-map'),

                    index = index + 1,

                    val = $(el).find('input[type=text]').val();

                if (val) {

                    $(el).append('<input type="hidden" data-metatype="hidden" name="' + id + '.' + groupNumber + '_productprop.property" value="' + metaProp + '" />');

                    $(el).append('<input type="hidden" data-metatype="hidden" name="' + id + '.' + groupNumber + '_productprop.exact" value="true" />');

                    $(el).append('<input type="hidden" data-metatype="hidden" name="' + id + '.' + groupNumber + '_productprop.value" value="' + val + '" />');

                    groupNumber++;

                }//if

            });

        }//end function _handleFullTextFilter

        function _submitForm() {

            _removeOldValues();

            _handleProductTextFilter();

            Dam.Search.Util.find();

        }//end function _submitForm

        $(document).on('keyup', '.producttextpredicate', function (e) {

            if(e.keyCode === 13) {

                e.stopPropagation();

                e.preventDefault();

                _submitForm();

            }

        });

        $(document).fipo('tap', 'click', '[data-type=producttext] button', function() {

            _submitForm();

        });

    });

})(document, Granite.$);

=======================================

As well as custom .jsp and custom query builder.

When we try to submit the search in the search bar from the custom field by calling Dam.Search.Util.find() the browser console throws an error "Cannot read property 'go' of undefined" referring to contentApi in Adobe's dam.admin.search.predicates.coral

function _submitSearchForm(data) {

        var contentApi = $('.foundation-content').adaptTo('foundation-content'),

            args = Array.prototype.slice.call(arguments, 0),

            MODAL_HTML =

                "<div class=\"coral-Modal-header\">"

                    + "<h2 class=\"coral-Modal-title coral-Heading coral-Heading--2\"></h2>"

                    + "<i class=\"coral-Modal-typeIcon coral-Icon coral-Icon--sizeS\"></i>"

                    + "<button type=\"button\" "

                    + "class=\"coral-MinimalButton coral-Modal-closeButton\" "

                    + "data-dismiss=\"modal\">"

                    + "<i class=\"coral-Icon coral-Icon--sizeXS coral-Icon--close "

                    + "coral-MinimalButton-icon\"></i>" + "</button>" + "</div>"

                    + "<div class=\"coral-Modal-body legacy-margins\"></div>"

                    + "<div class=\"coral-Modal-footer\"></div>",

            errorModal = $("<div />", {"class": "coral-Modal", "id": "searchquery-failure" }).html(MODAL_HTML).hide();

        //var spinner = $('<div style=" position: fixed; top: 50%; left: 50%;" class="coral-Wait coral-Wait--large"></div>');

       // $('.foundation-content').overlayMask('show', spinner);

        var url = $formSelector.attr("action");

        if (!url || url.trim() === "") {

            url = Granite.HTTP.externalize('/mnt/overlay/dam/gui/content/commons/sidepanels/search/items/searchpanel/result.html');

        }

        _buildFormData();

        if (url.indexOf('?') == -1) {

            url += '?';

        }

        if (!(url.slice(-1) == '?' || url.slice(-1) == '&')) {

            url += '&';

        }

        contentApi

            .go(url + $.param(fd))

            .done(function() {

                $('.foundation-content').overlayMask('hide');

            })

            .fail(function (response) {

                if (response.statusText != "abort") {

                    $('.foundation-content').overlayMask('hide');

                    $('body').append(errorModal);

                    var failureModal = new CUI.Modal({

                        element: errorModal,

                        heading: Granite.I18n.get('Error'),

                        type: 'error',

                        content: Granite.I18n.get("Search has encountered an internal error"),

                        buttons: [{

                            label: Granite.I18n.get('Close'),

                            className: 'coral-Button--primary',

                            click: function (evt) {

                                this.hide();

                            }

                        }]

                    });

                    failureModal.modal('show');

                }

            });

    }

All that was working in 6.1 but not in 6.3.

Hopefully this makes it a bit more clear. Thanks

Bobby