question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

allowCreate={true} does not work in in 1.0.0

See original GitHub issue

Is allowCreate={true} planned to be added, or is it a bug? If latter, when would this be added?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:5
  • Comments:40 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
labkey-nickacommented, Jun 15, 2016

@ryanzec created pull request #999 which implements allowCreate amongst other things.

7reactions
mldangelocommented, Jan 30, 2016

Hey everyone!

I figured out a (very) hacky way around this.

If you overide filterOptions with something like this:

filterOptions: function (options, filter, currentValues) {
  var filteredOptions = [];
  if (filter && filter.length >= 1){ // If a filter is present
    _.each(options, function(option){
    if (option.value.toLowerCase().trim().indexOf(filter.toLowerCase().trim()) > -1) {
      filteredOptions.push(option);
    }
  });
  }
  else { // Show everything available that's not already selected if no filter is used
    _.each(options, function(option){
      if (!_.contains(_.pluck(currentValues, 'value'), option.value)){
        filteredOptions.push(option);
      }
    });
  }
  // Only display  `Add ${filter}` if no other options are available 
  if (filteredOptions.length == 0 && filter) {
    filteredOptions.push({label: `Add ${filter}`, value: filter, create:true});
  }
  return filteredOptions;
},

And then handleChange with something like this:

handleSelectChange: function (value) { // value is an array of values -- I write bad code 
  _.each(value, function (singleValue) {
    if (singleValue.create){
      singleValue.create = false;
      singleValue.label = singleValue.value.trim();
      // I'm using a more complex slugify function here
      singleValue.value = singleValue.label.toLowerCase();
    }
  });
  console.log('You\'ve selected:', JSON.stringify(value));
  this.setState({ value });
},

Finally, when I define Select, I use the following configuration

filterOptions={this.filterOptions}
onChange={this.handleSelectChange}

Notice that allowCreate is not used.

Notice my underscore dependency. You could eliminate the _.each loops with for (var value of myArray) syntax. And the _.contains and _.pluck with ES6 set syntax. I’ll refactor this after dinner.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Minecraft 1.0.0 Server Problem - 1.0 Update Discussion
I am running Windows Vista Home Premium (Not the best, but it was free). ... My problem is running the new Minecraft 1.0.0...
Read more >
2019-January.txt - Jboss List Archives
Odata V4 Batch processing does not work as teiid/olingo rejects "Accept: ... <artifactId>jboss-jaxws-api_2.3_spec</artifactId> <version>1.0.0.
Read more >
Table of Contents - GitHub Pages
Diagnosing Issues. Migration Guide From Teiid 8.x. Caching Guide. Results Caching. Materialized Views. External Materialization. Internal Materialization.
Read more >
Documents PDF | PDF | Command Line Interface - Scribd
Avoid Classloading Issues: If you are using a servlet or other type of web application to create the DefaultCacheManager for the cache, be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found