1. #11
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,527
    Vote Rating
    379
    jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future

      0  

    Default


    Hi Patrick,

    my answers follow:

    Quote Originally Posted by pludikhu View Post
    Saki

    It's the echo.php which caught my eye. I couldn't understand why you would have it echo the $_POST-ed data ... where would it be sent to? To the client???
    echo.php is there purely for the demonstration purposes and/or debug. You post your form and you get back data that was really posted. Nothing else.

    And yes, data is send back to client.
    So I dug into it and tried to understand how it worked exactly.
    There are two server side scripts: echo.php and validate.php both of them being demo-only. validate.php handles validation requests sent after each keystroke (after some delay) and echo.php handles form submit.
    PHP being more or less my piece of cake and being very strict on server side validation I modified the echo.php as follows:
    Yes, this is one of possible server side validations however it ceases to be "echo" script anymore and it becomes "validate" script.
    So first of all: I do not believe that any piece of data that should be used later on the server (or stored in a database or whatever), could ever go without server side validation. Client side validation is very good to stop normal users from typing in something invalid but doesn't stand a chance against 'the bad guys out there'.
    Secondly, even if the fields have been validated before Submit, they should absolutely be re-validated after Submit because no one can say that the $_POST (or $_GET) came from this form they're using!
    Well, both client validation and server validation have their purposes. The degree and form and if to use one or both depends on nature of application. What's good is that we have tool to implement them easily.
    Because we now have something to say to our users, we may want to show the success/failure reason from the success function of the submit:
    PHP Code:
    ...
            ,
    buttons:[{
                 
    text'Submit'
                
    ,formBind:true
                
    ,handler:function() {
                    
    form.getForm().submit({url:'echo.php'method:'post'success:function(formaction){Ext.MessageBox.alert('Info'action.result.reason);}})
                }
            }]
    ... 
    Yes, one of the possible ways of announcing an invalid input is to show a message box. Of course, this is not the only way and in some cases is undesirable. For example, I use remote validation to check if the value entered is unique by searching a database table server side. Validation is triggered by keyup event (after some delay). Showing a message box after a couple of keystrokes would be very irritating in this case. Therefore, I just mark the form field invalid with reason shown in QuickTip.
    One last thing and again, it's not a criticism, it's meant to be constructive: could it be that the
    PHP Code:
        var submit = function() {
            
    form.getForm().submit({url:'echo.php'method:'post'});
        } 
    just after the QuickTips is also some stray leftover code?

    Anyway, it works fine without it ;-) and I thank you a lot because I'll be using your code in the application I'm writing for the Flemish Red Cross here.

    Thanks!

    Patrick
    Yes, it's stray code. It's not in the tutorial anymore but could be left in the downloaded code.
    Jozef Sakalos, aka Saki

    Education, extensions and services for developers at new http://extjs.eu
    News: Grid Search Plugin, ExtJS 5 Complex Data Binding using MVVM


  2. #12
    Ext User
    Join Date
    Nov 2007
    Posts
    10
    Vote Rating
    0
    weazle is on a distinguished road

      0  

    Default Problem with preset Values

    Problem with preset Values


    Hi Saki,
    since this is my first post in the forums, first of all: ExtJS is great, thanks to all people who spent their time making it become what it is now.

    I've been playing around with the RemoteValidation extension, works like a charm. The only thing I've come across is, when I have preset values in the Fields (i.e. fields have a value at the time the form is rendered), remote validation is not done as I would have expected.

    Example field configuration:
    Code:
    {
        "allowBlank": false,
        "plugins": [Ext.ux.plugins.RemoteValidator],
        "rvOptions": {"url": "actions/validate.jsp"},
        "name": 22,
        "xtype": "field",
        "value": 1.2,
        "fieldLabel": "Fuel"
    }

    In the rendered HTML-Form, each field with a preset value is marked invalid, telling me that server validation has not been performed yet. What I would expect is that validation of preset fields is already done when the form is rendered. So I changed the "render part" of your plugin a little bit:

    Code:
    // install event handlers on field render field.on({ render:{single:true, scope:field, fn:function() { this.remoteValidationTask = new Ext.util.DelayedTask(this.validateRemote, this); this.el.on('keyup', this.filterRemoteValidation, this);
    // START NEW CODE -- validate preset values if (field.getValue()) { this.remoteValidationTask.delay(this.remoteValidationDelay); } // END }}
    });
    This solves my problem. But since I'm pretty new to the whole library, I wonder if it is "the" way to do it. I also wanted to share this in case other people having the same problem. What do you think about it?

    Regards,
    Benjamin

  3. #13
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,527
    Vote Rating
    379
    jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future

      0  

    Default


    If you're absolutely sure that fields with preset values are valid you can set remoteValid flag to true to save server round trips.
    Jozef Sakalos, aka Saki

    Education, extensions and services for developers at new http://extjs.eu
    News: Grid Search Plugin, ExtJS 5 Complex Data Binding using MVVM


  4. #14
    Ext User
    Join Date
    Nov 2007
    Posts
    10
    Vote Rating
    0
    weazle is on a distinguished road

      0  

    Default


    Quote Originally Posted by jsakalos View Post
    If you're absolutely sure that fields with preset values are valid you can set remoteValid flag to true to save server round trips.
    Works perfect for me, thank you!

  5. #15
    Ext JS Premium Member christocracy's Avatar
    Join Date
    Oct 2006
    Location
    Montreal
    Posts
    381
    Vote Rating
    0
    christocracy is on a distinguished road

      0  

    Default Great Plugin

    Great Plugin


    Great plugin, mr JSakalos. just what I needed.

    2 things.

    I didn't see a way to prevent server-validation firing until client-validation passed. I added this:
    (eg: I use this on an airport-code field -- I don't want validation firing until minLength: 3 is satisfied)

    Code:
    // private - remote validation request
    validateRemote:function() {
        if (!validate.call(this)) { return false; } // <-- why server-validate if client-validation isn't valid??
    2. I attached the plugin to ComboBox, therefore I need to validate on "rawValue".
    Code:
    // private - remote validation request
                ,validateRemote:function() {
                    if (!validate.call(this)) { return false; } // <-- why server-validate if client-validation isn't valid??
                    
                    this.rvOptions.params = this.rvOptions.params || {};
                    this.rvOptions.params.field = this.name;
                    
                    #####################################
                    # changed this line to check for ComboBox
                    this.rvOptions.params.value = (!this instanceof Ext.form.ComboBox) ? this.getValue() : this.getRawValue();
                    Ext.Ajax.request(this.rvOptions);
                }

  6. #16
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,527
    Vote Rating
    379
    jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future

      0  

    Default


    Great! You're free to modify or improve this plugin for you needs...

    I just wouldn't wait with server validation until 3 letters as 2 letter code can be invalid...
    Jozef Sakalos, aka Saki

    Education, extensions and services for developers at new http://extjs.eu
    News: Grid Search Plugin, ExtJS 5 Complex Data Binding using MVVM


  7. #17
    Ext JS Premium Member christocracy's Avatar
    Join Date
    Oct 2006
    Location
    Montreal
    Posts
    381
    Vote Rating
    0
    christocracy is on a distinguished road

      0  

    Default Bug, RemoteValidator, isValid, disabled

    Bug, RemoteValidator, isValid, disabled


    *** bug ***

    Ext.ux.plugins.RemoteValidator::isValid

    Problem:
    when field is disabled, isValid will still validate upon the state of "remoteValid"

    Solution:
    Code:
    // private
                ,isValid:function(preventMark) {
                    if (this.disabled) { return true; }     // <--- fix: when field is disabled, return true immediately.           
                    return isValid.call(this, preventMark) && this.remoteValid;
                }

  8. #18
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,527
    Vote Rating
    379
    jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future

      0  

    Default


    Yes, you're right. Thank's for debugging.
    Jozef Sakalos, aka Saki

    Education, extensions and services for developers at new http://extjs.eu
    News: Grid Search Plugin, ExtJS 5 Complex Data Binding using MVVM


  9. #19
    Sencha User
    Join Date
    Aug 2007
    Posts
    32
    Vote Rating
    0
    attiato is on a distinguished road

      0  

    Default


    Hi everybody,
    i have some trouble with using remoteValidation plugin.
    It seems like the field value sent, is always the same, even if i type different text in the field.
    What could be the problem?
    I check with firebug.
    Example: first time i type "tr",
    firebug post is: value: tr,
    then i continue typing "try",
    firebug post is: value: tr,
    and so on...
    What could be the problem?
    I don't think the problem is the plugin, but i post this here, because maybe someone else had this problem and knows how to solve it.
    my input looks like this:
    PHP Code:
    var textfield = new Ext.form.TextField({
            
    allowBlank:false
            
    name:"somename"
            
    fieldLabel:'Insert name',
            
    plugins:[Ext.ux.plugins.RemoteValidator],
                    
    rvOptions: {
                
    url:'t/validate.php'
            
    }
        }); 
    By the way, my form is in an Ext.Window. Could this be the problem?
    Last edited by attiato; 27 Feb 2008 at 8:50 AM. Reason: [SOLVED]

  10. #20
    Ext JS Premium Member christocracy's Avatar
    Join Date
    Oct 2006
    Location
    Montreal
    Posts
    381
    Vote Rating
    0
    christocracy is on a distinguished road

      0  

    Default Works for me

    Works for me


    I posted your code into one of my forms (which happens to exist upon a Window) and it works for me.