不同的Livevalidation取决于各州的Javascript不起作用

时间:2013-07-26 20:13:12

标签: javascript livevalidation

我在标准表单中使用了成功的Livevalidation。当我在JavaScript中使用修改后的表单中的Valdidation时,它将无法正常工作。

它应该像这些说明一样工作:

<Input type="Ratio" value="1">: Validation for "Submit" not necessary
<Input type="Ratio" value="-1">: Validation necessary
<Input type="Ratio" value="-2">: Validation necessary

第一个问题:

  • 当我选择“值-1”时,Livevalidation不起作用
  • 当我选择“值-2”时,Livevalidation正常工作
  • 当我选择“值-1”(在-2之后)Livevalidation工作

第二个问题:

  • 当我选择“值1”时,我可以“提交”表格
  • ,但....
  • 当我选择“值-1”或“值-2”并且Livevalidation处于活动状态时
  • 然后我选择“值1”(不需要Livevalidation)我无法“提交”表单

    <script type="text/javascript">
    function changeState(state) {
    
       var id = parseInt(state);
    
       if (id >= 0)
       {
            $('#new_delivery_address').hide("slow");
            $('#packstation').remove();
    
            // Livevalidation
            var title = new LiveValidation('title');
            var firstName = new LiveValidation('firstName');
            var lastName = new LiveValidation('lastName');
            var firm = new LiveValidation('firm');
            var street = new LiveValidation('street');
            var streetnumber = new LiveValidation('streetnumber');  
            var street2 = new LiveValidation('street2');        
            var plz = new LiveValidation('plz');    
            var city = new LiveValidation('city');  
            var tel = new LiveValidation('tel');
    
            title.destroy(true);
            firstName.destroy(true);
            lastName.destroy(true);
            firm.destroy(true);
            street.destroy(true);
            streetnumber.destroy(true);
            street2.destroy(true);
            plz.destroy(true);
            city.destroy(true);
            tel.destroy(true);
        }
       if (id == -2) 
       {
    
            // Code
            // Code
            // ...
    
            // Livevalidierung
            var title = new LiveValidation('title');
            var firstName = new LiveValidation('firstName');
            var lastName = new LiveValidation('lastName');
            var firm = new LiveValidation('firm');
            var street = new LiveValidation('street');
            var street2 = new LiveValidation('street2');        
            var plz = new LiveValidation('plz');    
            var city = new LiveValidation('city');  
            var tel = new LiveValidation('tel');    
    
            firstName.add( Validate.Presence);
            lastName.add( Validate.Presence);
            street.add(Validate.Presence);
            street2.add(Validate.Presence);
            plz.add(Validate.Presence);             
            plz.add(Validate.Numericality);
            plz.add(Validate.Length, { minimum: 4, maximum: 5 } );
            city.add(Validate.Presence);
            streetnumber.destroy(true);
       }
       if (id == -1)
       {
    
            // Code
            // Code
            // ...
    
            // Livevalidierung
            var title = new LiveValidation('title');
            var firstName = new LiveValidation('firstName');
            var lastName = new LiveValidation('lastName');
            var firm = new LiveValidation('firm');
            var street = new LiveValidation('street');
            var streetnumber = new LiveValidation('streetnumber');      
            var street2 = new LiveValidation('street2');        
            var plz = new LiveValidation('plz');    
            var city = new LiveValidation('city');  
            var tel = new LiveValidation('tel');    
    
            firstName.add( Validate.Presence);
            lastName.add( Validate.Presence);
            street.add(Validate.Presence);
            streetnumber.add(Validate.Presence);
            plz.add(Validate.Presence);             
            plz.add(Validate.Numericality);
            plz.add(Validate.Length, { minimum: 4, maximum: 5 } );
            city.add(Validate.Presence);
            street2.destroy(true);
       }
    }
    
    function 123 () {
        // Code
        // Code
        // ...
    }
    

1 个答案:

答案 0 :(得分:0)

现在我找到了“第二个问题:......不能”提交“表格”的解决方案

我参与了禁用(功能)启用(功能)

的参数
    <script type="text/javascript">
function changeState(state) {

   var id = parseInt(state);

   if (id >= 0)
   {
        $('#new_delivery_address').hide("slow");
        $('#packstation').remove();

        // Livevalidation
        var title = new LiveValidation('title');
        var firstName = new LiveValidation('firstName');
        var lastName = new LiveValidation('lastName');
        var firm = new LiveValidation('firm');
        var street = new LiveValidation('street');
        var streetnumber = new LiveValidation('streetnumber');      
        var street2 = new LiveValidation('street2');        
        var plz = new LiveValidation('plz');    
        var city = new LiveValidation('city');  
        var tel = new LiveValidation('tel');    

        title.destroy(true);
        firstName.destroy(true);
        lastName.destroy(true);
        firm.destroy(true);
        street.destroy(true);
        streetnumber.destroy(true);
        street2.destroy(true);
        plz.destroy(true);
        city.destroy(true);
        tel.destroy(true);

        title.disable(true);
        firstName.disable(true);
        lastName.disable(true);
        firm.disable(true);
        street.disable(true);
        streetnumber.disable(true);
        street2.disable(true);
        plz.disable(true);
        city.disable(true);
        tel.disable(true);
    }
   if (id == -2) 
   {

        // Code
        // Code
        // ...

        // Livevalidierung
        var title = new LiveValidation('title');
        var firstName = new LiveValidation('firstName');
        var lastName = new LiveValidation('lastName');
        var firm = new LiveValidation('firm');
        var street = new LiveValidation('street');
        var street2 = new LiveValidation('street2');        
        var plz = new LiveValidation('plz');    
        var city = new LiveValidation('city');  
        var tel = new LiveValidation('tel');    

        title.enable(true);
        firstName.enable(true);
        lastName.enable(true);
        firm.enable(true);
        street.enable(true);
        street2.enable(true);
        plz.enable(true);
        city.enable(true);
        tel.enable(true);

        lastName.add(Validate.Presence);
        street.add(Validate.Presence);
        street2.add(Validate.Presence);
        plz.add(Validate.Presence);             
        plz.add(Validate.Numericality);
        plz.add(Validate.Length, { minimum: 4, maximum: 5 } );
        city.add(Validate.Presence);
        streetnumber.destroy(true);
        streetnumber.remove(true);  
   }
   if (id == -1)
   {

        // Code
        // Code
        // ...

        // Livevalidierung
        var title = new LiveValidation('title');
        var firstName = new LiveValidation('firstName');
        var lastName = new LiveValidation('lastName');
        var firm = new LiveValidation('firm');
        var street = new LiveValidation('street');
        var streetnumber = new LiveValidation('streetnumber');      
        var street2 = new LiveValidation('street2');        
        var plz = new LiveValidation('plz');    
        var city = new LiveValidation('city');  
        var tel = new LiveValidation('tel');    

        title.enable(true);
        firstName.enable(true);
        lastName.enable(true);
        firm.enable(true);
        street.enable(true);
        streetnumber.enable(true);
        street2.enable(true);
        plz.enable(true);
        city.enable(true);
        tel.enable(true);

        lastName.add(Validate.Presence);
        street.add(Validate.Presence);
        streetnumber.add(Validate.Presence);
        plz.add(Validate.Presence);             
        plz.add(Validate.Numericality);
        plz.add(Validate.Length, { minimum: 4, maximum: 5 } );
        city.add(Validate.Presence);
        street2.destroy(true);
        street2.remove(true);   
   }
}

function 123 () {
    // Code
    // Code
    // ...
}

但“第一个问题”仍然存在:

  • 当我选择“值-1”时,Livevalidation不起作用
  • 当我选择“值-2”时,Livevalidation正常工作
  • 当我选择“值-1”(在-2之后)Livevalidation也可以

现在还增加了禁用/启用功能:

  • 当我选择“值-1”时,输入字段已启用
  • 然后我选择“值1”输入字段显示
  • 当我再次选择“值-1”时,输入字段仍然显示!!
  • 仅当我选择“值-2”
  • 然后再次选择“value -1”input-fields works