Применение Normalizer method in jQuery Validation для обрезания пробелов с полей имени пользователя и пароля. Однако результат, отправленный обратно на сервер, не применяется. Я понимаю, что я никогда не буду предполагать, но только вопрос из любопытства - это ожидаемый результат?jquery validation normalizer - значение, которое применяется с обрезкой, не отправляется на сервер
Например: Используйте значения внутри кавычек Имя: "тест "Пароль:" C F1234 "
После нормализации из console.log значения
Имя пользователя:" тест" Пароль:» C F1234 "
Но с
submitHandler
form.submit()
отправляет значения как , введенные пользователем.
Я применил это неправильно?
$(document).ready(function(){
\t $("#login-form").validate({
\t \t rules: {
\t \t \t username:{
\t \t \t \t required:true,
\t \t \t \t normalizer:function(value){
console.log('user pre-trim:'+value);
console.log('user post-trim:'+$.trim(value));
\t \t \t \t \t return $.trim(value);
\t \t \t \t },
\t \t \t \t email:true,
\t \t \t },
\t \t \t password:{
\t \t \t \t required:true,
\t \t \t \t normalizer:function(value){
console.log('pwd pre-trim:'+value);
console.log('pwd post-trim:'+$.trim(value));
\t \t \t \t \t return $.trim(value);
\t \t \t \t },
\t \t \t \t
\t \t \t },
\t \t \t
\t \t },
\t \t errorContainer: "#errorMessageContainer",
\t \t errorLabelContainer: "#errorMessageContainer ul",
\t \t errorElement: "li",
\t \t messages: {
\t \t \t username:{
\t \t \t \t required:"Email cannot be left empty",
\t \t \t \t email:"Must be an Email address"
\t \t \t },
\t \t \t password: {
\t \t \t \t required: "Password Cannot Be Left Empty",
\t \t \t \t
\t \t \t }
\t \t }
\t \t ,
\t \t invalidHandler: function(form, validator) {
//Can something be done here?
console.log('invalidContainer');
\t \t },
\t \t submitHandler:
\t \t \t function(form) {
\t \t \t \t form.submit();
\t \t \t }
\t });
\t
\t displayErrorContainer();
});
function displayErrorContainer(){
\t var child = $("#errorMessageContainer").children("ul").html();
\t console.log('ftn: msg displayErrorContainer:'+child);
\t if(typeof child !== "undefined" && child.length > 0){
\t \t //console.log("show the error-container");
\t \t $("#errorMessageContainer").show();
\t }else{
\t \t //console.log("hide the error-container");
\t \t $("#errorMessageContainer").hide();
\t }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="http://cdn.jsdelivr.net/jquery.validation/1.15.0/jquery.validate.min.js"></script>
<div id="errorMessageContainer">
<ul><li>Username and Password do not match</li></ul>
</div>
<form id="login-form" request="POST">
<input id="username" name="username" type="text" />
<input id="password" name="password" type="password" />
<button type="submit">Submit</button>
</form>
@mcv, ваш вопрос был «я внедрил это ** IN ** правильно» ... – Sparky