包括来自另一个页面的Boostrap模态;t验证表单
Include a Boostrap modal from another Page Doesn't validate form
我知道这个问题已经回答了很多次了,Jquery相当于PHP的include
我的问题是,当我加载文件时,就像页面已经加载一样,验证表单没有任何效果。。。如果我使用php include或require_一旦它像一个魅力一样工作,问题是有很多页面是基于Html的,我不想把整个网站变成php。
基本:我得到了一个名为whatever.Html的Html页面:
<html>
<head>
</head>
<body>
<div class="container" >
content here...
<div id="footer_holder"></div>
</div>
<!-- /.container -->
<!-- jQuery and all JS -->
<script src="js/jquery.js"></script>...
</body>
</html>
在最后,我包括一个页脚,其中包含2个模式:
<!-- Request Modal -->
<div class="modal fade" id="requestModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Solicita el Servicio</h4>
</div>
<div class="modal-body">
<form role="form" id="requestModal" action="goto..." method="post">
<div class="form-group">
<label class="sr-only" for="exampleInputEmail1">Telefono</label>
<input type="text" class="form-control" name="telefono" placeholder="telefono de Contacto" required>
</div>
<div class="form-group">
<label for="textArea" class="sr-only">Textarea</label>
<textarea class="form-control" rows="3" placeholder="Mensaje" name="mensaje" required></textarea>
</div>
<div class="form-group">
<div id="form_request_result"></div>
</div>
</div>
<div class="modal-footer">
<button type="reset" class="btn btn-default"><i class="fa fa-eraser"></i>Borrar</button>
<button type="submit" id="myRequestButton" class="btn btn-ghost"><i class="fa fa-send"></i>Enviar</button>
</form>
</div>
</div>
</div>
</div>
<!-- Signin Modal Not rdy yet-->
<footer id="footer_design">
<!-- Footer Content -->
</footer>
然后我得到了一个custom.js文件,其中所有的代码都放在一个加载中
$(document).ready(function(){
jQuery(function(){
jQuery('#footer_holder').load('footer.html');
});
some other codes... Then validate form when user fire modal
$('#requestModal').formValidation({
framework: 'bootstrap',
err: {
container: 'tooltip'
},
icon: {
valid: 'fa fa-check',
invalid: 'fa fa-times',
validating: 'fa fa-refresh'
},
locale: 'es_ES',
fields: {
telefono: {
validators: {
notEmpty: {
message: 'The username is required'
}
}
},
mensaje: {
validators: {
notEmpty: {
message: 'The password is required'
}
}
}
}
});
所以,当我打开whatever.html时,一切都很顺利,页脚加载到页面内部,一切都好,但是,当用户调用Modal并单击提交按钮时,它不会验证。。。我所能想到的是页面已经加载,并且在启动验证时表单不存在,但我不知道如何在java/jquery上检查。。。就像我之前说的,如果我使用require_once'footer.html',它会起作用,我希望得到任何帮助,谢谢。
这个footer.html
加载似乎封装在两个document.ready事件处理程序中。只要此代码在页面上比#footer_holder
div运行得更远,那么两个document.ready包装器都是不必要的。它们甚至可能会让你慢一点:http://encosia.com/dont-let-jquerys-document-ready-slow-you-down/
由于.load()
方法接受在请求完成后运行的回调,因此最好立即加载内容,然后在加载footer.html
后使用该回调初始化验证。
jQuery('#footer_holder').load('footer.html', function() {
$('#requestModal').formValidation({
framework: 'bootstrap',
err: {
container: 'tooltip'
},
icon: {
valid: 'fa fa-check',
invalid: 'fa fa-times',
validating: 'fa fa-refresh'
},
locale: 'es_ES',
fields: {
telefono: {
validators: {
notEmpty: {
message: 'The username is required'
}
}
},
mensaje: {
validators: {
notEmpty: {
message: 'The password is required'
}
}
}
}
});
});
相关文章:
- 我想使用模态通过php文件发送邮件,并且我希望在提交关闭后关闭pop
- 打开一个模态并将其链接到AngularJS中的指令
- SemanticUI模态not onDeny/onApprove事件未激发
- 有没有比在app.js上绑定模块名称更好的方法来动态加载视图模型和视图以显示模态
- 如何通过所选索引(AngularJS)在模态弹出窗口中显示数据
- 包含数据库中相关信息的开放模态
- bootstrap消除模态并显示另一个模态
- 模态提示-如何重写此代码
- 包括来自另一个页面的Boostrap模态;t验证表单
- 模态窗口yii2中的Ajax验证数据
- 在模态中使用 jquery 验证器后,从表单中重置/删除类
- 模态弹出窗口验证 AngularJS
- 正在验证多模态.以前的数据验证
- yii在模态对话框上激活表单验证
- Richfaces 3.3.2 GA基于验证有条件地显示模态面板
- 在表单验证上显示模态
- 在模态表单中处理服务器端验证的最佳实践
- 模态对话框验证ASP.NET/bootstrap
- 如何创建一个模态弹出登录时,用户没有经过身份验证
- 验证不会在模态上触发