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

'onSelect' return undefined or incorrect element when using search module #2059

Closed
fuhaiq opened this issue Apr 4, 2015 · 7 comments
Closed
Milestone

Comments

@fuhaiq
Copy link

fuhaiq commented Apr 4, 2015

Hi,

I am using search module for tag suggestion, here's html code

<div class="ui category tag search">
   <div class="ui icon input">
      <input class="prompt" type="text" placeholder="search tags...">
      <i class="search icon"></i>
   </div>
   <div class="results"></div>
</div>

and this is js code

$.fn.api.settings.api = {
        'tag search': '/tag/search?keywords={query}'
    };
$('.ui.tag.search').search({
        apiSettings: {
            action: 'tag search'
        },
        type: 'category',
        onSelect: function(result, response) {
            console.log(result)
            return false;
        }
    })

This is json returned from server.

{
  "success": true,
  "results": {
    "category1": {
      "name": "Category 1",
      "results": [
        {
          "title": "S1",
          "description": "Optional Description1"
        },
        {
          "title": "S2",
          "description": "Optional Description2"
        },
        {
          "title": "S3",
          "description": "Optional Description3"
        }
      ]
    },
    "category2": {
      "name": "Category 2",
      "results": [
        {
          "title": "S10",
          "description": "Optional Description10"
        }
      ]
    }
  }
}

All the results displayed correctly, I want do some js hack when clicking the element, so I use onSelect callback.
'S10' is logged correctly, but 'S2' and 'S3' returned 'undefined' in console after click
2

More weird is when I click 'S1', console shows 'S10' element
4

Please take a look, thanks!

@jlukic
Copy link
Member

jlukic commented Apr 4, 2015

There were fixed related to this in one of the last patch releases. I'm on my phone but check closed issues.

Are you using latest?

@fuhaiq
Copy link
Author

fuhaiq commented Apr 5, 2015

@jlukic Yes. I am using 1.11.6. And this could be reproduced when using the master version from download as well
5

@jlukic
Copy link
Member

jlukic commented Apr 9, 2015

Thanks for the clarification. I'll take a look

@jlukic
Copy link
Member

jlukic commented Apr 14, 2015

Investigating this now, thanks for your patience.

jlukic added a commit that referenced this issue Apr 14, 2015
jlukic added a commit that referenced this issue Apr 14, 2015
@jlukic
Copy link
Member

jlukic commented Apr 14, 2015

I've reworked the offending method, it was a pretty poor implementation previously, and some of the variable names were a bit confusing.

I've verified against your example using the new $.api({ mockResponse: 'foo'}); syntax which I've also added as a new feature.

jlukic added a commit that referenced this issue Apr 14, 2015
@jlukic jlukic closed this as completed Apr 14, 2015
@jlukic
Copy link
Member

jlukic commented Apr 14, 2015

Available with 2.0

MrFusion42 added a commit to MrFusion42/Semantic-UI that referenced this issue Apr 14, 2015
* next: (32 commits)
  Semantic-Org#2092 rebuild dist
  Add comments to search settings
  Rlsnotes Semantic-Org#2059 Semantic-Org#2070
  Fixes Semantic-Org#2059 Semantic-Org#2070 rewrite object search used in search module to be much less obtuse
  Fix debug  Semantic-Org#2059 Semantic-Org#2070
  Add mock response async, yahoooo related to Semantic-Org#2059 Semantic-Org#2070
  Semantic-Org#2059 Finish ability to mock responses in API
  Similar Semantic-Org#2092 add ability to mock server response using function
  Semantic-Org#2092 RLSNOTES & Cred
  Remove debug Semantic-Org#2092
  Semantic-Org#2092 Add onResponse callback to allow for response transformations
  Semantic-Org#2070 - dont continue loop unnecessarily, clarify variable names
  Add Semantic-Org#2113 Add accordion on event, update rlsnotes
  Publish tasks fail with latest git due to add syntax
  Rlsnotes 1.11.7
  Build version 1.11.7
  Backport flex fix for cards Semantic-Org#2069 Semantic-Org#2021 Semantic-Org#2105
  More name consolidation Semantic-Org#2101
  More obvious name for merge copy Semantic-Org#2101
  NPM Update should only update default theme folder (not whole theme path) Semantic-Org#2101
  ...
@fuhaiq
Copy link
Author

fuhaiq commented Jul 1, 2015

Cheers!

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

No branches or pull requests

2 participants