1. #1
    Sencha User
    Join Date
    Mar 2008
    Posts
    82
    Vote Rating
    0
    safewolf is on a distinguished road

      0  

    Post Scope of textfield's validator,and a prblem about ajax validator

    Scope of textfield's validator,and a prblem about ajax validator


    Hi, everyone

    i have problem now.

    You know, when i add a listener to the textfield, i can set the scope like this:

    Code:
    textfield.on(“blur”,handler,scope);
    but in the form panel, i want to add a validator to the textfield, and want to set the listener's scope to the panel
    so , this is my code

    Code:
    MyPanel = function() {
    	this.validator = function(value) {
    		Ext.Ajax.request({
    					url : myUrl,
    					method : 'POST',
    					params : {
    						account : value,
    						guid : this.getForm().findField("guid").getValue()
    					},
    					success : function(response, action) {
    					},
    					failure : function(response, options) {
    					}
    				});
    		return true;
    	}
    
    	MyPanel.superclass.constructor.call(this, {
    				items : [{
    							xtype : 'hidden',
    							name : 'guid',
    							value : 'this is guid',
    							invalidText : 'Invalid!'
    						}, {
    							xtype : 'textfield',
    							name : 'name',
    							validationEvent : 'blur',
    							validator : this.validator
    						}]
    
    			});
    
    }
    
    Ext.extend(MyPanel, Ext.FormPanel, {});

    this code will report this.getForm() is undefined,
    and by using firebug, "this" here is the textfield

    so how can i use this.getForm() here?

    and another problem:
    i want to validate the field by using ajax request
    how can i validate the field?
    because the validator function can't return the result from the ajax response

  2. #2
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,251
    Vote Rating
    73
    Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold

      0  

    Default


    'this' will be the field and not the form, unless you override the scope using
    Code:
    validator: this.validator.createDelegate(this)

  3. #3
    Sencha User
    Join Date
    Mar 2008
    Posts
    82
    Vote Rating
    0
    safewolf is on a distinguished road

      0  

    Default


    thanks very much!

    But, do you know how to do the ajax validation?
    the valiadtor function can't return result from the ajax result
    How should i do can make the function return the correct value?

  4. #4
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,251
    Vote Rating
    73
    Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold Condor is a splendid one to behold

      0  

    Default


    Have a look at the RemoteValidator plugin (see User Extensions forum).

  5. #5
    Sencha User
    Join Date
    Mar 2008
    Posts
    82
    Vote Rating
    0
    safewolf is on a distinguished road

      0  

    Default


    thanks !

  6. #6
    Sencha Premium Member Troy Wolf's Avatar
    Join Date
    May 2007
    Location
    Kansas City
    Posts
    243
    Vote Rating
    2
    Troy Wolf is on a distinguished road

      0  

    Thumbs up


    I try to architect my application objects in such a way that the scope is natural, but it never fails, if the app has any complexity at all, I end up needing to fudge some things here and there. The way I've solved the problem described by safewolf is to create the reference I need upon object instantiation.

    You can add whatever custom properties you want to any object. In the example, below, the current object scope (this) is what I know I'll want to access later in my validator function. Instead of 'this', you could put any object you want to access later.

    Code:
    ...
    name: 'myTextfield',
    parentScope: this,
    width: 200,
    ...
    Then, for example, when my field validator function is called and 'this' is the textfield, I can do something like this:

    Code:
    this.parentScope.foo();
    If this is wrong, I don't want to be right.

Similar Threads

  1. Validator on a Grid's TextField
    By ald_2008 in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 5 Mar 2009, 10:23 AM
  2. TextField validator
    By villemustonen in forum Ext GWT: Help & Discussion (1.x)
    Replies: 2
    Last Post: 2 Oct 2008, 2:44 AM
  3. [FNR] Basic validator messages dissapear when using Validator
    By staffan in forum Ext GWT: Bugs (1.x)
    Replies: 6
    Last Post: 29 Aug 2008, 7:17 AM
  4. [SOLVED] [Javascript] Ext2: How to scope an object in validator
    By franck34 in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 26 Mar 2008, 12:37 AM

Thread Participants: 2

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar