我想使用来自Material-UI的 TextField和react-final-form ( https://github.com/final-form/react-final-form )。
主要问题是“如何获得values
对象?”
我无法从 TextField 中获取它。
结果是:
我已经尝试过不同的例子,但没有任何效果。
我的代码:
import React from 'react';
import TextField from '@material-ui/core/TextField';
import Button from '@material-ui/core/Button';
import Card from '@material-ui/core/Card';
import './loginForm.css';
import { Form, Field } from 'react-final-form';
const handleSubmit = (event, values) => {
console.log('onsubmit event target ', event.target);
event.preventDefault();
console.log('onSubmit values: ', values);
};
const onChange = (event) => {
console.log('on changed: ', event.target.value);
};
const LoginForm = () => (
<Card className="card">
<Form
onSubmit={handleSubmit}
onChange={onChange}
render={({ values }) => (
<form className="login-form" onSubmit={handleSubmit}>
<Field
name="pin"
component={TextField}
id="standard-name"
label="PIN"
value={values}
onChange={onChange}
/>
<Button
type="submit"
onClick={handleSubmit}
variant="contained"
color="primary"
className="login-btn"
>
Sign in
</Button>
</form>
)}
/>{' '}
</Card>
);
export default LoginForm;
版本:
"@material-ui/core": "^3.9.2",
"react-final-form": "^4.0.2",