Last active
October 28, 2015 12:25
-
-
Save khoand0000/6c5192aae2a2d6260206 to your computer and use it in GitHub Desktop.
using parsley with bootstrap
ref: http://stackoverflow.com/questions/22217735/getting-parsley-2-x-working-with-bootstrap-3-correctly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.Parsley.options.successClass = "has-success"; | |
window.Parsley.options.errorClass = "has-error"; | |
window.Parsley.options.errorsWrapper = "<p class='help-block'></p>"; | |
window.Parsley.options.errorTemplate = "<span></span>"; | |
window.Parsley.options.classHandler = function (el) { | |
return el.$element.closest(".form-group"); // is used to put successClass or errorClass | |
}; | |
window.Parsley.options.errorsContainer = function (el) { | |
return el.$element.closest(".form-group"); // is used to put successClass or errorClass | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// display error messages is wrong if using parsley with bootstrap-datetimepicker (https://eonasdan.github.io/bootstrap-datetimepicker/) | |
// solution: add errorsContainer callback to handle element will add errorsWrapper | |
$("form").parsley({ | |
successClass: "has-success", | |
errorClass: "has-error", | |
classHandler: function (el) { | |
return el.$element.closest(".form-group"); // is used to put successClass or errorClass | |
}, | |
errorsContainer: function (el) { | |
return el.$element.closest(".form-group"); | |
}, | |
errorsWrapper: "<p class='help-block'></p>", | |
errorTemplate: "<span></span>" | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ref: http://stackoverflow.com/questions/22217735/getting-parsley-2-x-working-with-bootstrap-3-correctly | |
$("form").parsley({ | |
successClass: "has-success", | |
errorClass: "has-error", | |
classHandler: function (el) { | |
return el.$element.closest(".form-group"); // is used to put successClass or errorClass | |
}, | |
errorsWrapper: "<p class='help-block'></p>", | |
errorTemplate: "<span></span>" | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment