1

additional-methods.jsファイルで提供されるメソッドを使用するメソッドを作成しようとすると、私は意図した検証を取得します。しかし、ユーザがadditional-methods.jsファイルに定義されている例外を表示するのではなく、間違った値を入力した場合、現在ヒントに使用されている現在の要素のタイトルが表示されます。エラーメッセージの代わりにタイトルを使用するjQuery検証プラグイン

私JavaScriptは次のようになります。フォームの存在の関連部分で

//setup input validation 
       validator = form.validate({ 
        rules: { 
         city: { 
          required: true, 
          lettersonly: true 
         } 
        } 
       }); 

    $('input, textarea').blur(function(){ 
        element = $(this); 

        // if the user gave no value then show the this field is required 
        if(element.val() == element.attr('title')){ 
         refreshError(element, 'This field is required'); 
        }else if(element.val() == '') { //if the value is empty then check if it was required, also check if it had an input hint 
         //if the element is required display the error message 
         if(element.hasClass('required')){ 
          refreshError(element, 'This field is required'); 
         } 

         //if the title exists then we assume it is the input hint 
         if(element.attr('title') != ''){ 
          element.val(element.attr('title')); 
          element.addClass('inputHint'); 
         } 
        }else{ 
         //if we got input validate it 
         response = element.valid(); 
         //if we got an error clear the old one(conditional on existance), and display the new one. Otherwise clear any old error 
         if(!response){ 
          this.defaultShowErrors(); 
         }else{ 
          errorId = element.attr('id')+'Error'; 
          $('#'+errorId).remove(); 
         } 
        } 
       }); 

<label for="city">City:</label> 
<input type="text" name="city" id="city" class="required inputHint" title="Your city here" /> 

任意のアイデアを私が間違っているの何にとして?私はjQuery Validator plugin

NBの1.9.0バージョンを使用しています:addMethod() of jQuery validation plugin display error from title attributeのが、試した後:私は読書の後に頭の上に釘を打ったと思った私は何も変わっていないことが判明

    //setup input validation 
       validator = form.validate({ 
        rules: { 
         city: { 
          required: true, 
          lettersonly: true 
         } 
        }, 
        messages: { 
         city: { 
          lettersonly: "you must give a valid city" 
         } 
        } 
       }); 

+0

あなたは本当に追加-methods.jsファイルの内容のように、十分な情報を提供していません。私の提案は 'console.info' JavaScript文を使って動作を記録/トレースして、代わりにそのタイトルが使われている理由を調べることです。 – jmort253

+2

私は髪を引き抜いている間にそれをやっていましたが、最終的にはプラグインにタイトルを無視するように設定する方法がありました:ignoreTitle:true。私は一度私は応答を投稿することができますこれをフォローアップします。 – xenador

答えて

1

私はこのエラーに遭遇したとignoreTitleオプションに出くわした:

//setup input validation 
validator = form.validate({ 
    ignoreTitle: true, 
    rules: { 
     city: { 
      required: true, 
      lettersonly: true 
     } 
    }, 
    messages: { 
     city: { 
      lettersonly: "you must give a valid city" 
     } 
    } 
}); 
関連する問題