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

Cloudinary select fields break other Relationship fields when using select: true #3848

Closed
autoboxer opened this issue Jan 6, 2017 · 3 comments

Comments

@autoboxer
Copy link
Contributor

Steps to reproduce the behavior

  1. Create a model with at least one Relationship field and one CloudinaryImage field.
  2. Load the model in the Admin UI
  3. Try to make a selection using the Relationship field

Expected behavior

The value you are trying to select should now populate the Relationship field

Actual behavior

The dropdown menu stays open and freezes without making the selection

@autoboxer
Copy link
Contributor Author

Here's what I've found so far:

Making any selections in the Relationship field calls loadAsyncOptions(input, state, callback) in node_modules/react-select/src/Select.js. In this function there's a loop:

if (this.props.cacheAsyncResults) { // included because it may be useful
    for (var i = 0; i <= input.length; i++) {

This loop executes once for each select field on the page when the model is initially loaded, which doesn't thrown an error, and again when a selection is made in any Select, Relationship, and I believe CloudinaryImage and CloudinaryImages fields. The input argument for the loadAsyncOptions(input, ...) function is an Array containing an Object for populated Relationship fields, and an empty Array for non-populated Relationship fields. The issue seems to be that the value for input for unpopulated CloudinaryImage fields is undefined, causing a JavaScript error when checking input.length in the for loop.

@autoboxer autoboxer changed the title Cloudinary select fields break other Relationship fields Cloudinary select fields break other Relationship fields when select: true Jan 6, 2017
@autoboxer autoboxer changed the title Cloudinary select fields break other Relationship fields when select: true Cloudinary select fields break other Relationship fields when using select: true Jan 6, 2017
@autoboxer
Copy link
Contributor Author

following from the fix by LiquidHelium in his commit 'Don't cache relationship options', a similar change to the CloudinaryImage field type fixes this as well.

Changing:

<div className='image-select'>
    <Select
        placeholder='Search for an image from Cloudinary ...'
        className='ui-select2-cloudinary'
        name={this.props.paths.select}
        id={'field_' + this.props.paths.select}
        asyncOptions={getOptions}
    />
</div>

to:

<div className='image-select'>
    <Select
        placeholder='Search for an image from Cloudinary ...'
        className='ui-select2-cloudinary'
        name={this.props.paths.select}
        id={'field_' + this.props.paths.select}
        asyncOptions={getOptions}
        cacheAsyncResults={false}
    />
</div>

fixes the issue. Creating a pull request for the change.

JedWatson added a commit that referenced this issue Jan 10, 2017
fixes Cloudinary select fields break other Relationship fields when using select: true (#3848)
@JedWatson
Copy link
Member

Should be fixed by #3849

trongthanh added a commit to naustudio/keystone that referenced this issue Jan 16, 2018
…am/v0.3.x into release/two-language-main-vi

* commit 'c38b366c7b1bf01448c8ece7c36e1bb6eb195186': (63 commits)
  fixes Cloudinary select fields break other Relationship fields when using select: true (keystonejs#3848)
  Don't cache relationship options
  fix linter errors, I'm a little OCD
  implement fix to determine whether input param is string or object and act accordingly to set q  value
  Fix keystonejs#3207
  Removing hardcoded keystone references in the API
  0.3.22
  Update CHANGELOG
  Fix relationship inital display
  Allow local connections without forcing SSL
  Let's Encrypt support
  Fix to prevent the use of regex matching when applying an "exact" filter through the Keystone admin ui
  Convert req strings to number where needed
  keystonejs#3011 | Fix Date format option bug
  v0.3.21
  Updating changelog
  Only setting pretty local when it is undefined, ref keystonejs#2614
  v0.3.20
  Updating changelog
  keystonejs#3030 | fix Date unit tests
  ...

# Conflicts:
#	fields/types/boolean/BooleanField.js
#	index.js
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

No branches or pull requests

2 participants