Welcome Guest, Not a member yet? Register   Sign In
[solved] don't understand javascript variable scope; now talking about validation plugin
#14

[eluser]SPeed_FANat1c[/eluser]
Quote:
Code:
public function edit($page_id) {
    $field_should_be = 'foo';
    $data['form_contents'] = $this->page->id($page_id);
    $data['validations'] = json_encode(array(
        'first_name' => 'required|min(5)|max(10)',
        'last_name' => 'required',
        'email' => 'required|email',
        'other_field' => 'required|should_be('.$field_should_be.')'
    ));
    $this->load->view('form');
}

$field_should_be - yeah, if there is one, or few words, then ok. Bt what if there is let's say 1000 words. Its not efective and we need to check in database.

And if there is only one word I can easily to that with the same validation plugin - just add a custom method that takes that words from let's say hidden field and cheks if it maches or not.

Quote:Anyway, why the validation plugin is async? I recon because it doesn’t clock up the interface during request. I mean, what’s the point of AJAX if you have to wait for the request to finish? That defeats the whole purpose: you could do a ‘normal’ request just as easily, would take the same amount of time and it requires less effort to program.

I understand, AJAX in general should be asynchroniuos. But when we use "remote" method, I can't think of when it can be asynchroniuos. So I think when we decide to use "remote" it should automatically make asycn:false. This probably should be possible, I haven't writen a plugin ever, so don't know Smile


And I can show one more interesting thing. There is another way to validate with this plugin, but I didn't use it, because it need that button type submit.
Code:
$(".edit").validate({
        
         submitHandler:function(form) {
        
         form.submit();
        
        
        
        
        },
        rules: {
             input_pavadinimas: {
              required: true,
              maxlength: 20,
              remote: {
                url: "http://www.ylakiudarzelis.lt/admin_/info_psl/name_check_ajax",
                type: "post",
                data: {
                  
                    current_name: function(){
                        return $('input[name="name"]').val()
                    }
                  }
                //async:false,
                
                }    
            },
            
            text: {
                required: true
            }
            
        },
    
        
    });

And this validation works even without async:false. As I expect it to work.

So thats the mystery form me why it works diferently when I need submit when I don't have button type submit. Or I just made something different but just don't see. Or.. there is a bug in that plugin. As you can see there is callback, and in it we can put statement to submit form.

However, that does not work when button type is not submit.
Code:
$('input.save').click(function() {
        
        $('form').attr( 'target', '' );
        
        valid = $(".edit").validate({        
         //$(".edit").validate({
            submitHandler:function(form) {    
                
              
               //document.myform.submit();        //this line does not submit
                //form.submit();                //this line also does not submit
                
            //so this callback does not help, we still have to make async:false
              
               },
            rules: {
                 input_pavadinimas: {
                  required: true,
                  maxlength: 20,
                  //name_free: true    //custom metodas
                  remote: {
                      url: CI.base_url + "admin_/info_psl/name_check_ajax",
                      type: "post",
                      data: {
                      
                        current_name: function(){
                            return $('input[name="name"]').val()
                        }
                      },
                     // async:false
                  }
                
                },
                text: {
                    required: true
                }
                
            },
            messages: {
                input_pavadinimas:{
                    required: "Neįvedėte pavadinimo",
                    maxlength: "Maksimalus ilgis - 20 simbolių"
                },    
                
                text: {
                    required: "Neįvedėte teksto"
                }
            }
            
        }
                
        
        ).form();
        
        console.log(valid);     //this is executed before request completes, if async is not false
        //if(valid)                //so we cannot run this line if async is not false, because it will submit even if form is not valid
            //document.myform.submit();
    });


Messages In This Thread
[solved] don't understand javascript variable scope; now talking about validation plugin - by El Forum - 01-26-2011, 09:25 AM



Theme © iAndrew 2016 - Forum software by © MyBB