所以我有这个功能,当输入为空时,我需要禁用模式中的按钮。是否可以在函数内部放置一个函数?
canBeSubmitted() {
const { Department, Employee_Name, Address } = this.state;
return (
Department.length > 0 &&
Employee_Name.length > 0 &&
Address.length > 0
);
}
但当模式已经被点击我赋予它是空的,但该按钮再次启用它,它应该被禁用
handleSubmit(name, address,department){
const laman = {
'Employee_Name': name,
'Address': address,
'Department': department
}
return fetch('http://localhost:5118/api/employeedetails/PostEmployeeDetail?', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(laman)
})
.then(function(response) {
console.log(response)
return response.json();
})
.then((result)=> {
var jsonReturnedValue = [...this.state.jsonReturnedValue];
jsonReturnedValue.push(result);
this.setState({jsonReturnedValue})
//this is where i call the function but it doesnt work
this.canBeSubmitted()
this.refs.Name.value="";
this.refs.Address.value="";
this.refs.Department.value="";
// this.setState({ value: '' });
})
.catch(function(error) {
console.log(error);
})
这是我的按钮
<input type="button" className="btn btn-info"disabled={!isEnabled}
onClick = { this.handleSubmit.bind(
this, this.state.Employee_Name,
this.state.Address,
this.state.Department)
}
value =" Add Employee"
data-dismiss="modal"/>
所以我应该怎么办呢? –