Trying to place several input
inside a table, I have found an inconvenience, which is that it does not allow me to write anything in these, no matter how many things I do.
From what I read in my search, it cannot be placed in such a way.
Condition
this.state = {
energiaConsumida:{
enero:"",
febrero:"",
marzo:"",
abril:"",
mayo:"",
junio:"",
julio:"",
agosto:"",
septiembre:"",
octubre:"",
noviembre:"",
diciembre:""
},
}
inside table
<tr>
<td>
<input type="text"
placeholder="Enero"
value={this.state.energiaConsumida.enero}
onChange={this.updateFields.bind(this, 'consumoEnero')}
name="consumoEnero"
maxLength="4"/>
</td>
</tr>
function to update the inputs
updateFields(propertyName, event) {
let energyData = this.state.energiaConsumida;
const re = /^[0-9\b]+$/;
if (event.target.value == '' || re.test(event.target.value)) {
energyData[propertyName] = event.target.value;
this.setState({ energiaConsumida: energyData });
}
}
The problem is that you are trying to write to
this.state.energiaConsumida.consumoEnero
and the input value is taken fromthis.state.energiaConsumida.enero
.Change your parameter
consumoEnero
toenero