-
Notifications
You must be signed in to change notification settings - Fork 197
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
Error trying to use inputComponent #226
Comments
Released |
Actually, I reverted the fix. |
In [email protected], I still met this problem. I used the
Another questionThe How should I pass the Could you provide a full example to show me how to use Thx! |
@NevenLiang
The
The readme states that "all other props are passed to input".
There's one: the "smart" input ( |
@catamphetamine
|
No, |
OK, but I am still a bit confused about the data communication between If I don't set I create a codesandbox example, would you mind helping to finish the confusing part for me? Thank you very much!! |
You must set |
OK! I still have some questions:
I understand the purpose of |
It's not clear what you mean.
|
Please see the code sandbox . I don't know how to trigger the And the custom input component can't get the value of input. These are the things confuses me. |
I can answer questions if you post them here. |
import React from "react";
import PhoneNumber from "react-phone-number-input";
import TextField from "material-ui/TextField";
import MuiThemeProvider from "material-ui/styles/MuiThemeProvider";
import "react-phone-number-input/style.css";
class PhoneNumberInput extends React.Component {
state = {
number: ""
};
handleUpdate = number => {
console.log('Something has been changed.');
this.setState({
number: number
});
};
render() {
const { number } = this.state;
return (
<div>
<PhoneNumber
country="US"
placeholder="Phone Number"
value={number}
onChange={this.handleUpdate}
inputComponent={PhoneNumberTextField}
/>
<p>Input Value: {number}</p>
</div>
);
}
}
const PhoneNumberTextField = props => {
function handleTextFieldChange(value) {
// The value is Synthetic Event Object
// console.log(value);
console.log('Input Update.');
console.log('The value is: ');
console.log(props.value);
console.log('--------------')
}
return (
<MuiThemeProvider>
<TextField
id="phoneNumber"
floatingLabelText="Phone Number"
onChange={handleTextFieldChange}
/>
</MuiThemeProvider>
);
};
export default PhoneNumberInput; |
What's not working? const PhoneNumberTextField = ({ onChange, ...rest }) => {
return (
<MuiThemeProvider>
<TextField
{...rest}
onChange={(event) => onChange(event.target.value)} />
</MuiThemeProvider>
);
}; |
Yes, it works. Thanks you very much!! I am still a bit confused about this.
|
Again, it's not clear what you mean. |
const PhoneNumberTextField = ({ onChange, ...rest }) => {
return (
<MuiThemeProvider>
<TextField
{...rest}
onChange={(event) => onChange(event.target.value)} /> // <-- this line
</MuiThemeProvider>
);
}; In your code above, the type of parameter in This is the |
The argument to onChange is provided by MUI, not by this library.
…On Mon, 15 Jul 2019 at 07:47, NevenLiang ***@***.***> wrote:
const PhoneNumberTextField = ({ onChange, ...rest }) => {
return (
<MuiThemeProvider>
<TextField
{...rest}
onChange={(event) => onChange(event.target.value)} /> // <-- this line
</MuiThemeProvider>
);
};
In your code above, the type of parameter in props.onChange, which is
from <PhoneInput/>, should be string, event.target.value, not the event
object.
This is the onChange requirement of inputComponent talking about, right?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#226?email_source=notifications&email_token=AADUP36FMVVTQ7XUZCM3P4DP7P6M3A5CNFSM4GO5C73KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZ4WRVI#issuecomment-511273173>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADUP32HQPLRJA3HPXL32LDP7P6M3ANCNFSM4GO5C73A>
.
|
Where the Have I misunderstood the document? |
It's not clear what you mean. |
In docs, Is it clear? |
Yes, it says:
Don't you think this is true? |
This is what I mean. If the type of parameter passed to I think I understand it correctly. Thanks for your patience in answering lots of question of mine, ❤️. |
No. |
const PhoneNumberTextField = ({ onChange, ...rest }) => {
return (
<MuiThemeProvider>
<TextField
{...rest}
onChange={(event) => onChange(event.target.value)} /> // <-- this line
</MuiThemeProvider>
);
}; But at the line of code, How to explain them? |
No, it doesn't. |
But in the code Is the description in document not very accurate? Using the parameter passed to I suggest that you add some example like this, to the github page of this project. import React from 'react';
import TextField from 'material-ui/TextField';
import PhoneNumberInput from 'react-phone-number-input';
import 'react-phone-number-input/style.css';
<PhoneNumberInput
country="US"
placeholder="Phone Number"
value={this.props.model.phoneNumber.value}
onChange={this.props.handleChange}
inputComponent={PhoneNumberTextField}
/>
...
class PhoneNumberTextField extends React.Component {
setRef = ref => {
this.input = ref;
};
focus = () => {
this.input.focus();
};
render() {
// just extract `country` and `metadata` out of `props`,
// not passing to the input component
const {country, metadata, onChange, ...rest } = this.props;
return (
<TextField
{...rest}
id="phoneNumber" // not necessary
floatingLabelText="Phone Number" // not necessary
ref={this.setRef}
// `props.onChange` only accept string
onChange={event => onChange(event.target.value)}
/>
)
}
} |
No, it's not. |
Awesome, thanks, @NevenLiang, for getting me on the right track. Your adapter component is a good start. I've fixed a couple issues with it:
I've posted my version here if interested: https://codesandbox.io/s/integrate-react-phone-number-input-with-material-uicore-ohfwp |
@NevenLiang, did you ever develop this further? It looks like if you supply your own I was hoping that using a custom Automatic formatting of the phone number seems like something react-phone-number-input could/should do for you regardless of which |
I managed to get phone number formatting working with Material UI |
Yes, it is (for some reason).
I guess your point here is a valid one. Update: Released |
Hi,
I'm trying to use the property
inputComponent
with theInput
component from material-ui (https://material-ui.com/api/input/) but when I try to type something I get the errorUncaught TypeError: text.search is not a function
and I'm not sure what is the problem. The documentation of this property is a little bit simple and I couldn't understand what else I would need to do.The text was updated successfully, but these errors were encountered: