This the HTML and JavaScript code:
<html>
<head>
<style type="text/css">
#bootstrapSelectForm .selectContainer .form-control-feedback {
/* Adjust feedback icon position */
right: -15px;
}
</style>
<link href="css/bootstrap-select.min.css" rel="stylesheet"/>
<script src="js/bootstrap-select.min.js" type="text/javascript"> </script>
</head>
<body>
<form id="bootstrapSelectForm" method="post" class="form-horizontal">
<div class="form-group">
<label class="col-xs-3 control-label">Language</label>
<div class="col-xs-5 selectContainer">
<select name="language" class="form-control">
<option value=""></option>
<option value="arabic">Arabic</option>
<option value="english">English</option>
<option value="french">French</option>
<option value="german">German</option>
<option value="other">Other</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-xs-5 col-xs-offset-3">
<button type="submit" class="btn btn-default">Validate</button>
</div>
</div>
</form>
This is the code for JavaScript:
<script type="text/javascript">
$(document).ready(function() {
$('#bootstrapSelectForm')
.find('[name="language"]')
.selectpicker()
.change(function(e) {
// revalidate the language when it is changed
$('#bootstrapSelectForm').formValidation('revalidateField', 'language');
})
.end()
.formValidation({
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
excluded: ':disabled',
fields: {
language: {
validators: {
notEmpty: {
message: 'Please select your native language.'
}
}
}
}
});
});
</script>
</body>
</html>
I can't do the validation. I already did all the code but still can't find the solution.
This the HTML and JavaScript code:
<html>
<head>
<style type="text/css">
#bootstrapSelectForm .selectContainer .form-control-feedback {
/* Adjust feedback icon position */
right: -15px;
}
</style>
<link href="css/bootstrap-select.min.css" rel="stylesheet"/>
<script src="js/bootstrap-select.min.js" type="text/javascript"> </script>
</head>
<body>
<form id="bootstrapSelectForm" method="post" class="form-horizontal">
<div class="form-group">
<label class="col-xs-3 control-label">Language</label>
<div class="col-xs-5 selectContainer">
<select name="language" class="form-control">
<option value=""></option>
<option value="arabic">Arabic</option>
<option value="english">English</option>
<option value="french">French</option>
<option value="german">German</option>
<option value="other">Other</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-xs-5 col-xs-offset-3">
<button type="submit" class="btn btn-default">Validate</button>
</div>
</div>
</form>
This is the code for JavaScript:
<script type="text/javascript">
$(document).ready(function() {
$('#bootstrapSelectForm')
.find('[name="language"]')
.selectpicker()
.change(function(e) {
// revalidate the language when it is changed
$('#bootstrapSelectForm').formValidation('revalidateField', 'language');
})
.end()
.formValidation({
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
excluded: ':disabled',
fields: {
language: {
validators: {
notEmpty: {
message: 'Please select your native language.'
}
}
}
}
});
});
</script>
</body>
</html>
I can't do the validation. I already did all the code but still can't find the solution.
Share Improve this question edited Aug 28, 2015 at 20:24 j08691 208k32 gold badges269 silver badges280 bronze badges asked Aug 28, 2015 at 12:46 ikramlimikramlim 1031 gold badge2 silver badges12 bronze badges 5-
1
Did you include the
FormValidation
JS & CSS files ? – Arkni Commented Aug 28, 2015 at 14:45 -
And, you forgot to add
framework: 'bootstrap',
– Arkni Commented Aug 28, 2015 at 14:45 - how can I get FormValidation JS & CSS files – ikramlim Commented Aug 28, 2015 at 15:34
- 1 I saw a similar example at gibbon.co/c/72f8cf89-f248-429a-bb5b-33bcc39b2144/…. You need to import that file formvalidation.js. Find it somewhere. It isn't free from the official site. – MaXi32 Commented Aug 28, 2015 at 20:21
- As @MaXi32 said, the plugin is not free you have to purchase a license to use it. – Arkni Commented Aug 29, 2015 at 1:54
2 Answers
Reset to default 1Your code should look like this. The only thing missing for this to work is the formvalidation.js plugin which is not free.
$(document).ready(function() {
$('#bootstrapSelectForm')
.find('[name="colors"]')
.selectpicker()
.change(function(e) {
// revalidate the color when it is changed
$('#bootstrapSelectForm').formValidation('revalidateField', 'colors');
})
.end()
.find('[name="language"]')
.selectpicker()
.change(function(e) {
// revalidate the language when it is changed
$('#bootstrapSelectForm').formValidation('revalidateField', 'language');
})
.end()
.formValidation({
framework: 'bootstrap',
excluded: ':disabled',
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
colors: {
validators: {
callback: {
message: 'Please choose 2-4 colors you like most',
callback: function(value, validator, $field) {
// Get the selected options
var options = validator.getFieldElements('colors').val();
return (options != null && options.length >= 2 && options.length <= 4);
}
}
}
},
language: {
validators: {
notEmpty: {
message: 'Please select your native language.'
}
}
}
}
});
});
An alternative would be this (using the jquery.validate.js):
JSFIDDLE
$(document).ready(function () {
$('#bootstrapSelectForm').validate({
rules: {
language: {
required: true
}
},
highlight: function (element) {
$(element).closest('.control-group').removeClass('success').addClass('error');
},
success: function (element) {
element.text('OK!').addClass('valid')
.closest('.control-group').removeClass('error').addClass('success');
}
});
});
This is a similar example that can be found here
You need to import a package called formvalidation.js. It isn't free from the official site. If you want, you can purchase the package here
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744402516a4572460.html
评论列表(0条)