Bootstrap Validation - Java Eclipse

0

When I enter information in a text box, it is validated but another text box is automatically validated, as it would be so that the automatic text box is not validated. Here I leave an image and the code.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Mantenimiento del Paciente</title>

<link rel="shortcut icon" href="Imagenes/logo.ico">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-responsive.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/bootstrapValidator.css">
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="js/jquery-3.1.1.min.js"></script> 
<script src="js/bootstrapValidator.js"></script>

</head>
<body><br>
    <div class="container">
        <form class="form-horizontal" id="id_form">
            <fieldset>
                <legend style="text-align:center"><label>MANTENIMIENTO DEL PACIENTE</label></legend>
                <fieldset>
                    <legend><label>Datos del Paciente</label></legend>

                    <div class="form-group">
                        <label class="control-label col-xs-1">Código:</label>
                        <div class="col-xs-2">
                            <input type="text" class="form-control" readonly name="codigo">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-xs-1 control-label">Nombre:</label>
                        <div class="col-xs-4">
                            <input type="text" class="form-control" name="nombre"/>
                        </div>
                        <label class="col-xs-2 control-label">Apellidos:</label>
                        <div class="col-xs-4">
                            <input type="text" class="form-control" name="apellidos"/>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-xs-1 control-label">DNI:</label>
                        <div class="col-xs-2">
                            <input type="text" class="form-control" name="dni"/>
                        </div>
                        <label class="col-xs-4 control-label">Fecha de Nacimiento:</label>
                        <div class="col-xs-2">
                            <input type="date" class="form-control" name="fechaNacimiento"/>
                        </div>
                    </div>

                </fieldset>
            </fieldset>
        </form>
    </div>

<script>
$(document).ready(function() {
    $('#id_form').bootstrapValidator({
        framework: 'bootstrap',
        icon: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            nombre: {
                row: '.col-xs-4',
                validators: {
                    notEmpty: {
                        message: 'El nombre es un campo obligatorio'
                    },
                    regexp: {
                        regexp: /^[a-zA-Z\s]+$/,
                        message: 'The first name can only consist of alphabetical and space'
                    }
                }
            },
            apellidos: {
                row: '.col-xs-4',
                validators: {
                    notEmpty: {
                        message: 'El apellido es un campo obligatorio'
                    }
                }
            },
            dni: {
                row: '.col-xs-2',
                validators: {
                    notEmpty: {
                        message: 'DNI es un campo obligatorio'
                    },
                    integer: {
                        message: 'DNI solo admite números'
                    },

                    stringLength :{
                        message:'El DNI solo admite 8 números',
                        min : 8,
                        max : 8,
                    }
                }
            },            
        }   
    });

//     // Validate the form manually
//     $('#validateBtn').click(function() {
//         $('#id_form').bootstrapValidator('validate');
//     });
});
</script>
</body>
</html>

    
asked by Bruno 12.12.2016 в 19:08
source

1 answer

0

Try putting each control (and its label) into a different form-group:

<div class="form-group">
    <label class="col-xs-1 control-label">Nombre:</label>
    <div class="col-xs-4">
        <input type="text" class="form-control" name="nombre"/>
    </div>
</div>
<div class="form-group">
    <label class="col-xs-2 control-label">Apellidos:</label>
    <div class="col-xs-4">
        <input type="text" class="form-control" name="apellidos"/>
    </div>
</div>
    
answered by 13.12.2016 в 13:53