6

検証が機能しない理由がわかりません。さまざまな検証ツールを使用しようとしましたが、結果は常に有効として返されます..

エラーを見つけるには、もう一度目が必要です..

初めてスニペットを使用します。下のスニペットが正しいことを願っています..

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>Test Files</title>
		<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css" rel="stylesheet">
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      
		<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/jqBootstrapValidation/1.3.7/jqBootstrapValidation.min.js"></script>
		<script>
			$(function() {
                $("input,select,textarea").jqBootstrapValidation(
                    {
                        preventSubmit: true,
                        submitError: function($form, event, errors) {
                            // Here I do nothing, but you could do something like display 
                            // the error messages to the user, log, etc.
							alert("Not Valid!!");
                        },
                        submitSuccess: function($form, event) {
                            alert("OK");

                        },
                        filter: function() {
                            return $(this).is(":visible");
                        }
                    }
                );
            });
		</script>
	</head>
	<body>
		<nav class="navbar navbar-default" role="navigation">
			<div class="container-fluid">
				<div class="navbar-header">
					<button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#mainnav" aria-expanded="false">
						<span class="sr-only">Navigation Toggle</span>
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
					</button>
					<a class="navbar-brand" href="#">K</a>
				</div>
		</nav>
		<div class="container-fluid">
			<div class="panel panel-primary">
				<div class="panel-heading">
					<h3 class="panel-title">Form Name</h3>
				</div>
				<div class="panel-body">
					<div class="panel panel-default">
						<div class=btn-group" role="group" aria-label="true">
							<div class="btn-toolbar" role="toolbar" aria-label="true">
								<button type="button" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-repeat" aria-hidden="false"></span></button>
							</div>
						</div>
					</div>
					<div class="panel panel-default">
						<div class="panel-body">
							<ul class="nav nav-tabs">
								<li><a href="#first-tab" data-toggle="tab">Main<i class="fa"></i></a></li>
							</ul>
							<form class="form-inline" id="accountForm" method="post" class="form-horizontal">
								<div class="tab-content">
									<div class="tab-pane" id="first-tab">
										<!-- INPUT that need to be validated... -->
										<div class="input-group input-group-sm col-xs-12">
											<span class="input-group-addon" id="sizing-addon3">Serial Number (Only Accept Numbers)</span>
											<input 
												type="text" 
												data-validation-regex-regex="^[0-9]*$" 
												data-validation-regex-message="Only Numbers" 
												class="form-control" 
												placeholder="Serial Number" 
												aria-describedby="sizing-addon3"
											/>
										</div>
										<button type="submit" class="btn btn-primary">Test Validation <i class="icon-ok icon-white"></i></button>
									</div>
								</div>	
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</body>
</html>

4

1 に答える 1

5

私は2つの問題を見ました:-

次の行では、div クラスの後に引用符 " がないことに注意してください。これは主な問題ではありませんが、

<div class=btn-group" role="group" aria-label="true">

2 番目の問題は、jqBootstrapValidation では、コントロール グループ クラスを親 div に定義する必要があることです。したがって、以下を追加すると機能するはずです:-

<div class="control-group tab-pane" id="first-tab"> 

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>Test Files</title>
		<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css" rel="stylesheet">
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      
		<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/jqBootstrapValidation/1.3.7/jqBootstrapValidation.min.js"></script>
		<script>
			$(function() {
                $("input,select,textarea").jqBootstrapValidation(
                    {
                        preventSubmit: true,
                        submitError: function($form, event, errors) {
                            // Here I do nothing, but you could do something like display 
                            // the error messages to the user, log, etc.
							alert("Not Valid!!");
                        },
                        submitSuccess: function($form, event) {
                            alert("OK");

                        },
                        filter: function() {
                            return $(this).is(":visible");
                        }
                    }
                );
            });
		</script>
	</head>
	<body>
		<nav class="navbar navbar-default" role="navigation">
			<div class="container-fluid">
				<div class="navbar-header">
					<button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#mainnav" aria-expanded="false">
						<span class="sr-only">Navigation Toggle</span>
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
					</button>
					<a class="navbar-brand" href="#">K</a>
				</div>
		</nav>
		<div class="container-fluid">
			<div class="panel panel-primary">
				<div class="panel-heading">
					<h3 class="panel-title">Form Name</h3>
				</div>
				<div class="panel-body">
					<div class="panel panel-default">
						<div class="btn-group" role="group" aria-label="true">
							<div class="btn-toolbar" role="toolbar" aria-label="true">
								<button type="button" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-repeat" aria-hidden="false"></span></button>
							</div>
						</div>
					</div>
					<div class="panel panel-default">
						<div class="panel-body">
							<ul class="nav nav-tabs">
								<li><a href="#first-tab" data-toggle="tab">Main<i class="fa"></i></a></li>
							</ul>
							<form class="form-inline" id="accountForm" method="post" class="form-horizontal">
								<div class="tab-content">
									<div class="control-group tab-pane" id="first-tab">
										<!-- INPUT that need to be validated... -->
										<div class="input-group input-group-sm col-xs-12">
											<span class="input-group-addon" id="sizing-addon3">Serial Number (Only Accept Numbers)</span>
											<input 
												type="text" 
												data-validation-regex-regex="^[0-9]*$" 
												data-validation-regex-message="Only Numbers" 
												class="form-control" 
												placeholder="Serial Number" 
												aria-describedby="sizing-addon3"
											/>

										</div>
										<button type="submit" class="btn btn-primary">Test Validation <i class="icon-ok icon-white"></i></button>
									</div>
								</div>	
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</body>
</html>

于 2016-04-22T00:36:04.550 に答える