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

onInputChange event not firing for AsyncCreatable #1506

Closed
rubencodes opened this issue Jan 26, 2017 · 6 comments
Closed

onInputChange event not firing for AsyncCreatable #1506

rubencodes opened this issue Jan 26, 2017 · 6 comments

Comments

@rubencodes
Copy link
Contributor

I'm trying to do some realtime cleaning of input as shown on the README.MD:

function cleanInput(inputValue) {
      // Strip all non-number characters from the input
    return inputValue.replace(/[^0-9]/g, "");
}   

<Select
    name="form-field-name"
    onInputChange={cleanInput}
/>

However, when using this option with AsyncCreatable, I'm finding it doesn't run at all. I'm on version 1.0.0-rc.2.

@agirton
Copy link
Collaborator

agirton commented Jan 30, 2017

Hi @rubencodes can you give a reproducible case? I ran the test suite and confirmed that onInputChange is being called. Here is the test case I ran on the AsyncCreatable

it('should fire onInputChange', () => {
  let onInputChange = sinon.spy();

  createControl({ onInputChange });
  typeSearchText('a');
  expect(onInputChange, 'was called with', 'a');
});

@stahlmanDesign
Copy link

stahlmanDesign commented Feb 7, 2017

I also find it does nothing in 1.0.0-rc.3

<Select.Async
  onInputChange={ (input)=>{console.log(input)} }
/>

I wanted to use it to know when characters have been deleted with backspace to update my keyword.

Duplicate of #1283 and mentioned here #1257

@stahlmanDesign
Copy link

I realized that the function I was looking for is onInputKeyDown which works fine. I might have caused some confusion. I no longer think my issue may is related to the onInputChange problem some people are having.

@mhubenthal
Copy link
Contributor

mhubenthal commented Feb 22, 2017

@agirton I am seeing this issue as well for the Creatable component. The bug lies on these lines in that component:

onInputChange (input) {
	const { onInputChange } = this.props;

	if (onInputChange) {
		onInputChange(input);
	}

	// This value may be needed in between Select mounts (when this.select is null)
	this.inputValue = input;
}

Even though onInputChange() is called, the value is not returned. When I just use the Select component I am able to apply a masking function, whereas when using the Creatable component, that masking function value is never returned from the Creatable onInputChange call to the Select component. The function passed in as a prop is called, but the value is never returned up the call stack.

The correct code would look like this:

onInputChange (input) {
	const { onInputChange } = this.props;

	// This value may be needed in between Select mounts (when this.select is null)
	this.inputValue = input;

	if (onInputChange) {
		return onInputChange(input);
	}
}

cc: @JedWatson

@adrianojdesouza
Copy link

@agirton any news about this issue? I saw PRs for fix this and they had not merged

@JedWatson
Copy link
Owner

I think this has been addressed, although if the input value is mutated by onInputChange it is not returned, just used for loadOptions which is inconsistent with the way Select and Creatable handle the prop. I'm going to follow up in #2056

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

6 participants