2014-06-26 112 views
0

我在页面上使用Foundation-5的选项卡在选项卡上有一个表单。欧芹验证和标签

当网页加载完毕后,我得到以下错误:

You must bind Parsley on an existing element.

这个我想是因为形式是不是在当香菜被调用,因为非活动选项卡显示的DOM: none

$('form.parsley').parsley({ }) 

如何为我的窗体启用欧芹?

香菜正在调用是这样的:

(function($) { 
    $.entwine('ss.zenvalidator', function($) { 
     $('form.parsley').parsley({ 
      excluded: 'input[type=button], input[type=submit], input[type=reset], input[type=hidden], :hidden, .ignore-validation' 
     }); 

     $('.field').entwine({ 

      getFormField: function() { 
       var rtn = this.find('[name='+this.getFieldName()+'], [name="'+this.getFieldName()+'[]"]'); 
      }, 

      getFieldName: function() { 
       return this.attr('id'); 
      }, 

      getFieldValue: function() { 
       return this.getFormField().val(); 
      }, 

      evaluateEqualTo: function(val) { 
       return this.getFieldValue() === val; 
      }, 

      evaluateNotEqualTo: function(val) { 
       return this.getFieldValue() !== val; 
      }, 

      evaluateLessThan: function(val) { 
       num = parseFloat(val); 
       return this.getFieldValue() < num; 
      }, 

      evaluateGreaterThan: function(val) { 
       num = parseFloat(val); 
       return parseFloat(this.getFieldValue()) > num; 
      }, 

      evaluateContains: function(val) { 
       return this.getFieldValue().match(val) !== null; 
      }, 

      evaluateEmpty: function() { 
       return $.trim(this.getFieldValue()).length === 0; 
      }, 

      evaluateNotEmpty: function() { 
       return !this.evaluateEmpty(); 
      }, 

      evaluateChecked: function() { 
       return this.getFormField().is(":checked"); 
      } 


     }); 


     $('.field.validation-logic').entwine({ 
      onmatch: function() { 
       masters = this.getMasters(); 
       for(m in masters) { 
        this.closest('form').find('#'+masters[m]).addClass("validation-logic-master"); 
       } 
      }, 

      getLogic: function() { 
       return $.trim(this.getFormField().data('validation-logic-eval')); 
      }, 

      parseLogic: function() { 
       js = this.getLogic(); 
       result = eval(js); 
       return result; 
      }, 

      getMasters: function() { 
       return this.getFormField().data('validation-logic-masters').split(","); 
      } 

     }); 


     $('.field.optionset').entwine({ 

      getFormField: function() { 
       f = this._super().filter(":checked"); 
       return f; 
      } 

     }); 


     $('.field.optionset.checkboxset').entwine({ 

      evaluateHasCheckedOption: function(val) { 
       this.find(':checkbox').filter(':checked').each(function() { 
        return $(this).val() === val || $(this).getLabel() === val; 
       }) 
      }, 

      evaluateHasCheckedAtLeast: function(num) { 
       return this.find(':checked').length >= num; 
      }, 

      evaluateHasCheckedLessThan: function(num) { 
       return this.find(':checked').length <= num; 
      } 
     }); 

     $('.field input[type=checkbox]').entwine({ 
      getLabel: function() { 
       return this.closest('form').find('label[for='+this.attr('id')+']'); 
      } 
     }); 

     $('.field.validation-logic.validation-logic-validate').entwine({ 
      testLogic: function() { 
       this.getFormField().toggleClass('ignore-validation', this.parseLogic()); 
      } 
     }); 


     $('.field.validation-logic.validation-logic-exclude').entwine({ 
      testLogic: function() { 
       this.getFormField().toggleClass('ignore-validation', !this.parseLogic()); 
      } 
     }); 

     $('.field.validation-logic-master :text, .field.validation-logic-master select').entwine({ 
      onmatch: function() { 
       this.closest(".field").notify(); 
      }, 

      onchange: function() { 
       this.closest(".field").notify(); 
      } 
     }); 

     $('.field.validation-logic-master :checkbox, .field.validation-logic-master :radio').entwine({ 
      onmatch: function() { 
       this.closest(".field").notify(); 
      }, 

      onclick: function() { 
       this.closest(".field").notify(); 
      } 
     }); 

     $('.field.validation-logic-master').entwine({ 
      Listeners: null, 

      notify: function() { 
       $.each(this.getListeners(), function() { 
        $(this).testLogic(); 
       }); 
      }, 

      getListeners: function() { 
       if(l = this._super()) { 
        return l; 
       } 
       var self = this; 
       var listeners = []; 
       this.closest("form").find('.validation-logic').each(function() { 
        masters = $(this).getMasters(); 
        for(m in masters) { 
         if(masters[m] == self.attr('id')) { 
          listeners.push($(this)); 
          break; 
         } 
        } 
       }); 
       this.setListeners(listeners); 
       return this.getListeners(); 
      } 
     }); 
    }); 

})(jQuery); 

回答

1

我认为以下就足够了:(未经测试)

$('form.parsley').entwine({ 
    onmatch: function() { 
     $(this).parsley({ 
      excluded: 'input[type=button], input[type=submit], input[type=reset], input[type=hidden], :hidden, .ignore-validation' 
     }); 
    } 
}); 
+1

这确是足够了:) - 对其他任何人出现了,发现这一点,有很多其他的东西打破了这个我不得不首先消除 - 例如Facebook js,jquery在站点主js文件中的不同版本等。一旦那些被淘汰&它真的只是标签打破香菜这很好。谢谢! – Will