开发者

custom validation does not seem to get registered

Inside a tab, I have a form that is dynamically loaded via ajax. Since the name of the field is dynamic too(e.g. <input name='title1' id='title1', class='tRequired'>), I write a custom validation method inside the "on complete" like this. However, the custom code does not get executed (the alert never pops up) no matter what i try.

$.ajax
                (   
                    {   
                        url: 'index.php?func=trainingmgr&aAction=displayAddForm', <br>
                        type: 'GET',<br>
                        dataType: 'html',<br>
                        complete: function(req, err) 
                            {   
                                //Append response to the tab's body <br>
                                $(href, '#trainingTabs').append(req.responseText);

                                $.validator.addMethod
                                (   
                                    'tRequired', 
                                    function(value, element) 
                                    {   
                                        if(value == '')
       开发者_运维问答                                 { 
                                          alert('I am empty'); <====== Never pops up
                                          return true; 
                                        }
                                        else return false;
                                    },  
                                    '<br>Required field'
                                );  

                                $('#upload' + index).click
                                (   
                                    function() 
                                    { $('#addForm' + index).validate(); }
                                );  
                            }   
                    }   
                );  


Try

value == null


Similar to Jeremy's answer,

Try

value === ''
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜