我正在尝试对表单中的一个字段执行验证。
只有当该字段的值存在时,我才能调用 API,否则将抛出错误消息。
我尝试了 SweetAlert2 网站上的各种示例。我只想要对其中一个字段的验证。
Swal.fire({
title: 'Are you sure you want to Save the Notes?',
type: 'info',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes'
}).then((result) => {
console.log('result.value',result.value);
if (result.value) {
Swal.fire( {
title: 'Download Notes',
html:"<div class='b'><p>ID</p></div><input id='swal-input2' class='swal2-input' required/><div class='b'><p>Notes</p></div><input id='swal-input1' class='swal2-input' autofocus minlength='500' >",
confirmButtonText: 'Save',
preConfirm: (login) => {
console.log('document.getElementById(swal-input2).value',document.getElementById('swal-input2').value);
request_string = {
"Request":
[
{
"Col1": "value1",
"Col1": "value2",
"Col1": document.getElementById('swal-input2').value,
"Col1": document.getElementById('swal-input1').value,
}
]
};
fetch('API_URL', {
headers: {
'Accept': 'application/json, …
Run Code Online (Sandbox Code Playgroud) 在过去的几个月中,我一直在使用react js,只是了解了React的sweetalert bootstrap插件。成功更新组件时,屏幕上会出现一个对话框。在单击“单击此处”按钮后,history.push会被调用,它应该路由到其他页面,但出现错误
history.push未定义。
我用谷歌搜索了很多东西,并尝试了很多场景,但是都没有成功。
代码段:
class displayBlank extends Component {
render(){
<div id="displayDetails">
<DisplayDetails respData={this.state.respData} />
</div>
}
}
export default displayBlank;
class displayDetails{
handleUpdate()
{
// Body of HandleUpdate
swal({
title :"Customer Updated Successfully!",
icon : "success",
button: "Click Here!",
}).then((e) => { history.push('/blank');
});
}
render(){
<table>
<tr>
<td>
Table-Grid Contents
</td>
</tr>
</table>
<td>
<FormGroup controlId="formControlsDisabledButton" style={buttonalignment}>
<Button className="float-right" bsStyle="primary" type="submit" onClick={this.handleUpdate}>Save</Button>
{' '}
<Button className="float-right" bsStyle="primary" type="submit" disabled>Download</Button>
{' '}
</FormGroup>
</td>
}
}
Run Code Online (Sandbox Code Playgroud)