Добрый вечер.
Помогите пожалуйста решить проблему.
Проблема что-то связанное с input`ами.
Вот код:
import React, { Component } from 'react';
import '../styles/Register.css';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import { registerUser } from '../redux/actions/authActions';
class Register extends Component {
constructor() {
super();
this.state = { name: {inputValue: '', fieldActive: false}, email: '', password: '', password_confirmation: '', errors: {} };
this.handleSubmit = this.handleSubmit.bind(this);
this.updateInputValue = this.updateInputValue.bind(this);
this.activateField = this.activateField.bind(this);
this.disableFocus = this.disableFocus.bind(this);
}
handleSubmit(e) {
e.preventDefault();
const data = {
name: this.state.name,
email: this.state.email,
password: this.state.password,
password_confirmation: this.state.password_confirmation,
}
this.props.registerUser(data, this.props.history)
}
activateField(e) {
console.log('hello', e.target.id);
this.setState({
[e.target.id]: { fieldActive: true },
});
}
disableFocus(e) {
console.log('bye bye', e.target.id);
if (e.target.value === "") {
this.setState({
[e.target.id]: { fieldActive: false },
});
}
}
updateInputValue(e) {
this.setState({
[e.target.id]: { inputValue: e.target.value },
});
this.activateField(e);
e.preventDefault();
}
componentWillMount() {
if (this.props.auth.isAuthenticated) {
this.props.history.push('/')
}
}
componentWillReceiveProps(nextProps, nextContext) {
if (nextProps.auth.isAuthenticated) {
this.props.history.push('/')
}
if (nextProps.errors) {
this.setState({ errors: nextProps.errors })
}
}
render() {
return (
<div className="container">
<div className="row justify-content-center">
<div className="col-md-6">
<form onSubmit={this.handleSubmit}>
<div className="floating">
<label style={{zIndex: '-1'}} className={this.state.name.fieldActive ? "floating-label field-active" : "floating-label"}>Name</label>
<input type="text"
className="floating-label-input"
id="name"
value={this.state.name.inputValue}
onFocus={this.activateField}
onBlur={this.disableFocus}
onChange={this.updateInputValue}
/>
</div>
</form>
</div>
</div>
</div>
);
}
}
const mapStateToProps = (state) => ({
auth: state.auth,
errors: state.errors,
})
export default connect(mapStateToProps, { registerUser })(withRouter(Register));
Ошибка:
Все вроде работает, но почему-то ошибка...
Работает все это так:
Заранее спасибо!