开发者

custom validation does not seem to get registered

开发者 https://www.devze.com 2022-12-22 17:31 出处:网络
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 val

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

精彩评论

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