Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds noResults option #215

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Adds noResults option #215

wants to merge 1 commit into from

Conversation

dmitov
Copy link

@dmitov dmitov commented Jul 8, 2016

Adds noResults option.
False by default.

@elliotrpage
Copy link

Hello!

Sorry to barge in but I am rather keen to incorporate this feature into my own site and wanted to lend a hand in testing. I appreciate I am not the developer of EAC itself but hope this is of use.

When I have used this version of EAC I receive the error:
"Property 'noResults' does not exist in EasyAutocomplete options API."

Something that would be helpful is to provide some indication of how to call the "noResults" option (where it sits in the options block, for example).
Also, the large number of whitespace deletions makes finding the actual changes made to create the Noresults option very difficult to pin down!

Any questions let me know.

Thanks,
Elliot

@adamtheapiguy
Copy link

Hi Elliot,

Did you get it to work? from the look of it and the changes it looks like all you need to do is to just add noResult: true and if the no result, yu will get no result in the drop down, right?

Cheers,
adam

@elliotrpage
Copy link

I did not, I am afraid. After tooling around and posting the above note I shrugged and moved back to the main branch of EAC as testing was taking up a lot of time and I did not hear back.

@adamtheapiguy
Copy link

adamtheapiguy commented Oct 8, 2016

Hello Elliot,

I did a bit of digging into the code and I came up with the below:

in jquery.easy-autocomplete.min.js

Replace:

if (0!==l.length) {
void 0 !== c[i].header && c[i].header.length > 0 && f.append("

" + c[i].header + "
");
for (var m = 0, n = l.length; n > m && h < c[i].maxListSize; m += 1)
e = $("
  • "), function() {
    var a = m, b = h, f = c[i].getValue(l[a]);
    e.find(" > div").on("click", function() {
    t.val(f).trigger("change"), w = b, j(b), o.get("list").onClickEvent(), o.get("list").onChooseEvent()
    }).mouseover(function() {
    w = b, j(b), o.get("list").onMouseOverEvent()
    }).mouseout(function() {
    o.get("list").onMouseOutEvent()
    }).html(q.build(g(f, d), l[a]))
    }(), f.append(e), v.push(l[m]), h += 1
    }

    with:

    if (l !== undefined) {
    void 0 !== c[i].header && c[i].header.length > 0 && f.append("

    " + c[i].header + "
    ");
    for (var m = 0, n = l.length; n > m && h < c[i].maxListSize; m += 1)
    e = $("
  • "), function() {
    var a = m, b = h, f = c[i].getValue(l[a]);
    e.find(" > div").on("click", function() {
    t.val(f).trigger("change"), w = b, j(b), o.get("list").onClickEvent(), o.get("list").onChooseEvent()
    }).mouseover(function() {
    w = b, j(b), o.get("list").onMouseOverEvent()
    }).mouseout(function() {
    o.get("list").onMouseOutEvent()
    }).html(q.build(g(f, d), l[a]))
    }(), f.append(e), v.push(l[m]), h += 1
    } else {
    f.append("
  • noResults
  • ");
    }

    This would achieve 2 things:

    1. If there is no results, then the javascript won't crash and you need to reload the page.
    2. If no result, there should be an drop down menu item with noResult.

    number 1 above is achieved but number 2 is not so may be if you can help by defining what can we put in the else clause to have #2 achieved it would be great.

    Will keep digging.

    I highlighted the changed I have made above in bold text

    Will send it by email as it looks like the above is not rendered correctly.

    Cheers,
    adam

    @adamtheapiguy
    Copy link

    Hi Elliot,

    Here is what I have done:

    replaced the below block:

    if (0!==l.length) {

    void 0 !== c[i].header && c[i].header.length > 0 && f.append("<div class='eac-category' >" + c[i].header + "</div>");
    
    for (var m = 0, n = l.length; n > m && h < c[i].maxListSize; m += 1)
    
       e = $("<li><div class='eac-item'></div></li>"), function() {
    
           var a = m, b = h, f = c[i].getValue(l[a]);
    
           e.find(" > div").on("click", function() {
    
               t.val(f).trigger("change"), w = b, j(b), o.get("list").onClickEvent(), o.get("list").onChooseEvent()
    
           }).mouseover(function() {
    
               w = b, j(b), o.get("list").onMouseOverEvent()
    
           }).mouseout(function() {
    
               o.get("list").onMouseOutEvent()
    
           }).html(q.build(g(f, d), l[a]))
    
       }(), f.append(e), v.push(l[m]), h += 1
    

    }

    with the below block:

    if (l !== undefined) {

    void 0 !== c[i].header && c[i].header.length > 0 && f.append("<div class='eac-category' >" + c[i].header + "</div>");
    
    for (var m = 0, n = l.length; n > m && h < c[i].maxListSize; m += 1)
    
       e = $("<li><div class='eac-item'></div></li>"), function() {
    
           var a = m, b = h, f = c[i].getValue(l[a]);
    
           e.find(" > div").on("click", function() {
    
               t.val(f).trigger("change"), w = b, j(b), o.get("list").onClickEvent(), o.get("list").onChooseEvent()
    
           }).mouseover(function() {
    
               w = b, j(b), o.get("list").onMouseOverEvent()
    
           }).mouseout(function() {
    
               o.get("list").onMouseOutEvent()
    
           }).html(q.build(g(f, d), l[a]))
    
       }(), f.append(e), v.push(l[m]), h += 1
    

    } else {

     f.append("<li><div class='eac-item'>noResults</div></li>");
    

    }

    I highlighted the changes I have made in red.

    The if (l !== undefined) works and the javascript doesn't crash. The problem is the below block is where you can define what would be in the drop down list but for some reasons it doesn't work.

    else {

     f.append("<li><div class='eac-item'>noResults</div></li>");
    

    }

    Will keep digging. If you can find anything to help in the second block, please let me know.

    Cheers,
    adam


    From: Elliot Page [email protected]
    Sent: Tuesday, 4 October 2016 12:11 AM
    To: pawelczak/EasyAutocomplete
    Cc: Adam Ali; Comment
    Subject: Re: [pawelczak/EasyAutocomplete] Adds noResults option (#215)

    I did not, I am afraid. After tooling around and posting the above note I shrugged and moved back to the main branch of EAC as testing was taking up a lot of time and I did not hear back.

    You are receiving this because you commented.
    Reply to this email directly, view it on GitHubhttps://github.com//pull/215#issuecomment-251101788, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AK9fUqkK2TJl-1xNtFUFlf6gRTcbm1ofks5qwP7-gaJpZM4JH3zE.

    @kevinLay7
    Copy link

    I was able to get this working using @dmitov code. There is an error in the PR though. In his PR file: src/core.js Line 311 should be $listContainer.append("<li><div class='eac-item'>" + config.get("noResults") + "</div></li>");

    @adamtheapiguy
    Copy link

    Hi Elliot,

    I had a crack at this and I made it. I'm using custom templates to read from RESTful APIs and display the results in a drop down list.

    What I have done is that I have changed the RESTful API to have the return results as per the below in case no record is found.

    {
    "status": "ZERO_RESULTS",
    "predictions": [
    {
    "customerNumber": "No records found",
    "cn": "No records found",
    "dateOfBirth": "No records found",
    "addressLine1": "No records found",
    "addressSuburb": "No records found",
    "addressCountry": "No records found",
    "customerfacephotolocation": "No records found"
    }
    ]
    }

    In the EA JavaScript code:

        listLocation: "predictions",
        placeholder: "Start typing to search for customers",
        getValue: "customerNumber",
        template: {
                type: "custom",
                method: function(value, item) {
    
                if(item.customerNumber == "No records found"){
    
                return "No record found";
    
                }else{
    
                return "the html template with item values";
    
                }
    
        }
        },
        list: {
            onChooseEvent: function() {
                var value = $("#searchCustomers").getSelectedItemData().customerNumber;
                if(value == "No records found"){
                }else{
                     getCustomerDetails(value);
                }
            }
        }
    

    The above gave me the below results

    [cid:6ec7e826-0e5c-46a5-a2c2-60f64ad91dfd]

    If you have any questions, please let me know.

    Cheers,
    adam


    From: Elliot Page [email protected]
    Sent: Tuesday, 4 October 2016 12:11 AM
    To: pawelczak/EasyAutocomplete
    Cc: Adam Ali; Comment
    Subject: Re: [pawelczak/EasyAutocomplete] Adds noResults option (#215)

    I did not, I am afraid. After tooling around and posting the above note I shrugged and moved back to the main branch of EAC as testing was taking up a lot of time and I did not hear back.

    You are receiving this because you commented.
    Reply to this email directly, view it on GitHubhttps://github.com//pull/215#issuecomment-251101788, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AK9fUqkK2TJl-1xNtFUFlf6gRTcbm1ofks5qwP7-gaJpZM4JH3zE.

    @johann-beessip
    Copy link

    johann-beessip commented Mar 28, 2018

    Hi All,

    In case anyone else sees this , I've created a PR with the fix suggested by @kevinLay7 above.

    #340

    If you're using NPM I've also created a release on my fork with this functionality. See my PR for the release info.

    @@ -307,6 +307,10 @@ var EasyAutocomplete = (function(scope) {
    }
    }

    if (config.get("noResults") && counter == 0) {
    $listContainer.append("<li><div class='eac-item'>" + config.get("noResults + </div></li>"));
    Copy link
    Owner

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    There is an error here, you put brackets in wrong place, can you fix it?

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    None yet
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    7 participants