-
Notifications
You must be signed in to change notification settings - Fork 326
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
redux-form .change() has no effect on <Geosuggest /> #275
Comments
Here is a wrapper class that allows react-geosuggest to be used with redux-form:
It would be nice if the next major version of this library used the value/onChange pattern that most form related React components have adopted. |
We’ll keep that in mind for a new major. Feel free to submit a PR if you find a way to implement it without breaking! Hope the workaround works. |
Just in case someone wants to load google maps lib async:
And then just:
|
I don't want to get too excited, but this is working for me currently with Geosuggest and Redux-Form V7.2 import React, { Component } from 'react'
import PropTypes from 'prop-types'
import Geosuggest from 'react-geosuggest'
class CreateGeoSuggest extends Component {
render() {
const {
input,
meta: { touched, error },
name,
label,
required,
placeholder,
} = this.props
const maybeHasValue = (input.value)
? 'edit_filled'
: 'edit_empty'
const maybeHasError = (touched && error)
? 'form-text-input error'
: `form-text-input normal ${maybeHasValue}`
return (
<div className="edit_rowcontainer">
<label className="edit_row" htmlFor={name}>
<div className="edit_row-label">
{label}
{required && <span className="edit_asterisk">*</span>}
</div>
<div className="edit_row-item">
<Geosuggest
ref={el => this._geoSuggest = el} // eslint-disable-line
placeholder={placeholder}
inputClassName={maybeHasError}
name={name}
initialValue={input.value}
onSuggestSelect={(suggest) => {
if (!suggest) return input.onChange(null)
return input.onChange(suggest.label)
}}
{...input}
/>
</div>
</label>
{touched && (error && <span className="edit_required">{error}</span>)}
</div>
)
}
} Called like this: <Field
label=""
component={CreateGeoSuggest}
name="person_location"
placeholder="Enter Location"
/> The above code works correctly including with Redux-Form sync validation. Special thanks to the wizards above me in this thread. Pay special attention to my |
Ok, confirmed. The above code works nice for both create and edit scenarios. |
Hello, |
@Ezekiah use @amackintosh example but change |
Short description
Use
<Geosuggest />
in redux-formExpected results
<Geosuggest />
should work same way as outside redux-formredux-form should be able to aggregate/validate/manipulate/... value of
<Geosuggest />
Actual results
Everything works just great, except one very central problem.
redux-form can't manipulate the value of
<Geosuggest />
at all. Resulting in even bigger problems when implementing in FieldArray.Reproduction steps
Using this implementation shows redux-form updates the
input.value
as expected. But Geosuggest doesn't update.Additional Information
IMHO it's not totally clear if this is a bug or no bug.
Anyways: I'm sure there is a proper way to do this, or at least a workaround. Infos about those are highly appreciated.
The text was updated successfully, but these errors were encountered: