简体   繁体   English

Bootstrap-服务器端验证

[英]Bootstrap - Server-side validation

I have a modal in Bootstrap 3 which collects some data. 我在Bootstrap 3中有一个模态,可以收集一些数据。 If the entered ID already exists in a SQL table, I want to display a warning message in the modal - but the modal seems to disappear when the user clicks the [Save] button. 如果输入的ID在SQL表中已经存在,我想在模式中显示警告消息-但是,当用户单击[保存]按钮时,模式似乎消失了。

I can relaunch the modal which then correctly displays the exception - but the background becomes darker & darker each time the [Save] button is clicked. 我可以重新启动模态,然后正确显示异常-但每次单击[保存]按钮时,背景变得越来越黑。

Is there a more practical solution to prevent the modal from being closed if a server-side exception occurs - or at least to prevent the background from becoming progressively darker when the primary button is clicked? 是否有更实用的解决方案来防止在发生服务器端异常时关闭模式,或者至少是防止单击主按钮时背景逐渐变暗?

I understand that you are interacting with the server inside a modal. 我了解您正在与模式内的服务器进行交互。 You need to handle the hide event to check the response from server before letting it bubble. 您需要处理hide事件,以检查来自服务器的响应,然后使其冒泡。

$('#myModal').on('hide.bs.modal', function (e) {
  // check response from server and cancel event or let it bubble.
})

you need to handle event hide.bs.modal, do your validation and return false to prevent modal from closing 您需要处理事件hide.bs.modal,进行验证并返回false以防止模式关闭

http://getbootstrap.com/javascript/#modals-examples http://getbootstrap.com/javascript/#modals-examples

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM