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

Tag Input/Autocomplete: objects as items does not work #405

Closed
c-frater opened this Issue Jun 22, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@c-frater
Copy link
Contributor

c-frater commented Jun 22, 2017

Context

When using objects with {name, type} properties in the autocomplete data, the value is set to [object Object].

Expected Behavior

The value should use the inputMap result

Actual Behavior

It shows [object Object]

Possible Fix

Workaround

This detects when the new item that has been added is an object, removes it and replaces it with an inputMapped value.

tagInput.on('add', ({value, type}) => {
  if (hx.isObject(value)) {
    const newItems = tagInput.items()
    newItems.pop()
    newItems.push(inputMap(value))
    tagInput.items(newItems)
  }
})

Steps to Reproduce

const items = [
  {
    type: 'A',
    name: 'A Text'
  },
  {
    type: 'B',
    name: 'B Text'
  },
  {
    type: 'D',
    name: 'D Text'
  },
  {
    type: 'C',
    name: 'C Text'
  }
]

const inputMap = ({name}) => name

const ti = hx.tagInput({
    autocompleteOptions: {
      renderer: (elem, item) => {
        hx.select(elem).text(item.type)
      },
      inputMap: inputMap
    },
    autocompleteData: (term, cb) => {
      cb(items.filter(({name}) => name.indexOf(term) > -1))
    }
  })

hx.select('body')
  .append(ti)

Your Environment

  • Hexagon Version: 1.11.0
@dzheleznyakov

This comment has been minimized.

Copy link

dzheleznyakov commented Jan 22, 2018

It could be useful to add this info to the docs: https://www.hexagonjs.io/docs/tag-input/

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