1. #1
    Sencha User
    Join Date
    Feb 2011
    Posts
    106
    Vote Rating
    2
    wizkid is on a distinguished road

      0  

    Default EXTJS 4.0 Model and remote validation?

    EXTJS 4.0 Model and remote validation?


    How would I go about using the new EXTJS 4.0 model with remote business rules?

    For example let's say I am registering a user and we need to see if the user name / user id is not a duplicate. Client side validation in the model won't work in this case, we have to go to the web server.

    I was looking through the API docs, maybe I missed something? What I want to see is if that user name / user id is invalid to go to the server and find that out, then flag the field with the red validation halo, like client side validation errors.

    I know I can submit the whole model to the web server and then let my server throw an error of some nature, and then maybe have a pop-up alerting the user. But I think as a user there should be no UI difference between a client and server side client validation error.

    Does anyone have a code snippet to share on how to go about this?

  2. #2
    Ext JS Premium Member westy's Avatar
    Join Date
    Feb 2009
    Location
    Bath, UK
    Posts
    963
    Vote Rating
    72
    westy is just really nice westy is just really nice westy is just really nice westy is just really nice westy is just really nice

      0  

    Default


    Hi,

    Suppose you could override the fields validate method, then call to the server in there, setting the field as invalid when you get the response.

    I believe validate is meant to return true or false though, so is not meant to be asynchronous.

    Not quite sure how you're meant to set it's valid state, perhaps through getErrors()?

    Edit: Oh, that was the field specifically I was looking at.
    The model's validate returns the errors, so you would probably have to stall it's return somehow :/

  3. #3
    Sencha User
    Join Date
    Feb 2011
    Posts
    106
    Vote Rating
    2
    wizkid is on a distinguished road

      0  

    Default


    Hmmm maybe a custom validate function.... Yeah...

    Does anyone have an example? I know I am not the only one that needs this...

    Maybe a Extjs developer could chime in? I can create custom logic like the previous poster is saying. But I would of expected this to be part of the framework

    I just want to make sure that I am not missing something in the documentation since this is pre-release stuff... Or, you know, preview 3 will have it. If that's the case I don't want to "spin my wheels" coming up with something on my own.

  4. #4
    Ext JS Premium Member
    Join Date
    May 2008
    Posts
    186
    Vote Rating
    64
    sg707 is a jewel in the rough sg707 is a jewel in the rough sg707 is a jewel in the rough

      0  

    Default


    As of now, I can't even validate on the server side unless I throw in HTTP Status Code.

    The output of my server is
    Code:
    {"errors":{"name":"invalid name"},"success":false,"msg":"my message"}
    But when I execute

    Code:
        newUser.save( {
            success : function(user, operations) {
                console.log(operations.success);
            }
            
        });
    It still calls "success"..and operations think it's a "success" as well. Help, plz??

  5. #5
    Touch Premium Member pmarko's Avatar
    Join Date
    Dec 2007
    Location
    Ireland
    Posts
    58
    Vote Rating
    1
    pmarko is on a distinguished road

      0  

    Default


    I'm experiencing same issue. Would anyone explain us, how to do remote model validations proper way, please ? Thanks.

  6. #6
    Sencha User
    Join Date
    Jun 2008
    Posts
    157
    Vote Rating
    0
    wiznia is on a distinguished road

      0  

    Default


    I'm using 4.0.2 and it's working for me, if I return success:false, it calls the failure callback.
    But my problem is that it doesn't seem to be doing anything with the errors I pass back... Is there any way for the model to be aware of server side errors or it's just possible in the forms??

  7. #7
    Sencha User
    Join Date
    Jun 2011
    Posts
    2
    Vote Rating
    0
    sirtmp is on a distinguished road

      0  

    Default What about plugin

    What about plugin


    What about Saki's plugin?

    http://www.sencha.com/learn/legacy/P...emoteValidator

  8. #8
    Sencha User
    Join Date
    Jun 2008
    Posts
    157
    Vote Rating
    0
    wiznia is on a distinguished road

      0  

    Default


    mmmm, it's a nice plugin, but I thought since there's a validation in our new Ext models, why not be able to retrieve validation errors from the server? Besides it should be almost the same that we already have for forms...

  9. #9
    Sencha User
    Join Date
    Sep 2011
    Posts
    16
    Vote Rating
    0
    webleaf is on a distinguished road

      0  

    Default


    Quote Originally Posted by wiznia View Post
    mmmm, it's a nice plugin, but I thought since there's a validation in our new Ext models, why not be able to retrieve validation errors from the server? Besides it should be almost the same that we already have for forms...
    I need this, too...
    Do you find solution for this?

  10. #10
    Sencha User
    Join Date
    Jun 2008
    Posts
    157
    Vote Rating
    0
    wiznia is on a distinguished road

      0  

    Default


    Nope... Let me know if you do.

Similar Threads

  1. TextField with remote validation
    By Caolga in forum Community Discussion
    Replies: 25
    Last Post: 14 Sep 2012, 7:36 AM
  2. Ext.ux.MvcFormValidator - MVC 2 Client Side Model Validation with ExtJS
    By tdupont in forum Ext 3.x: User Extensions and Plugins
    Replies: 1
    Last Post: 1 Mar 2011, 9:22 AM
  3. Model Validation
    By ksystems in forum Sencha Touch 1.x: Discussion
    Replies: 3
    Last Post: 15 Jul 2010, 7:41 AM
  4. remote validation
    By ibcravi in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 3 Sep 2009, 10:53 AM

Thread Participants: 9