Hybrid View

  1. #1
    Sencha User
    Join Date
    Sep 2010
    Location
    Ft Myers, Fl
    Posts
    67
    Vote Rating
    0
    Gamer is on a distinguished road

      0  

    Default Newbie: help with factory function

    Newbie: help with factory function


    Hi everyone,
    Im working on this factory function and I have no idea what im doing wrong. Im getting this error from the chrome console "Uncaught SyntaxError: Unexpected token (" and I also put the JSON code into JSONlint and got this error message "syntax error, unexpected TINVALID at line 1
    Parsing failed"


    Code:
    Ext.ns('Ext.ux');
    //start of factory function
    Ext.ux.CarterRemoteCombo = function(config) {
        return new Ext.ux.form.ComboBoxAdd(Ext.apply({
      name: 'SiteID',
         fieldLabel: this.name,
      hiddenName: this.name,
      displayField: 'lookupname',
      originalwhere: 'this.name',
      valueField: 'lookupid',
      moegalReturnid: 'this.valueField',
      comboVarname: 'tblbillboard_siteID',
      allowBlank: false,
      forceSelection: true,
       //pageSize:50,
        listWidth: 300,
        triggerAction: 'all',
        typeAhead:true,
        minChars: 3,
        //mode: 'remote', defaults at remote
        lazyInit: false,
        //hideTrigger1: false, combo defaults at false
        //hideTrigger2: false, clear defaults at false
        hideTrigger3: true, //search
        //hideTrigger4: false, add defaults at false
    	listeners: {
    
    	collapse: function(combo) {	
    	
                if(this.startValue != this.getValue()){
                    UpdateDependentComboboxStore('this.comboVarname',this.getValue(),'this.name',5,'this.mode');
    				console.log(this.name);
    				console.log(this.getValue());
                }
    			add: function(this) {
                    loadwindow('Add Site','includes/table-insert.asp',true,'tableID=5&refreshType=combo&refreshID=tblbillboard_siteID',false);
            },
            lookup: function() {
                loadwindow('Search Site','includes/table-search.asp',true,'tableID=5&refreshType=combo&refreshID=tblbillboard_siteID&linktableID=&linkID='+this.store.baseParams.LinkID,true);			
            },
            render: function(this) {
                this.store.add(new Ext.data.Record({this.valueField:'40', this.displayField:'4000/4001CPA', linkedid:''}));
                this.setValue(40);           
                UpdateDependentComboboxStore('this.comvoVarname',40,'this.name',5,'this.mode');                    
            }
    			}
    	store: new Ext.data.JsonStore({
       proxy: new Ext.data.HttpProxy({
        url: 'includes/get-comboremote.asp',
        method: 'post'
       }),
               totalProperty: 'RecordCount',
       autoLoad: false,
            baseParams: {linkedid: "", allowNew: "true", allowSearch: "false", table: "tblsite", idname: "this.name", displayfield: "sitename", linkTableID: "", orderby: "this.name asc", where: "this.name", lookupID: 40},
    fields:['this.valueField', 'this.displayField', 'linkedid'],   
            id: 'this.valueField',
       root: 'Records',
       listeners: {
    load: function() {
                    if (this.startValue != ''){
    				if(this.store.find('this.valueField',this.startValue) != '-1'){
                     this.setValue(this.startValue);
         UpdateDependentComboboxStore('this.comboVarname',this.getValue(),'this.name',5,'this.mode');
                        }
                    }
                }
    			}
      })
      },
      }, config));  
      };
      Ext.reg('carterremotecombo', Ext.ux.CarterRemoteCombo);
    any insight is appreciated
    thanks,
    Gamer
    Danger Zone!

  2. #2
    Sencha User
    Join Date
    Sep 2010
    Location
    Ft Myers, Fl
    Posts
    67
    Vote Rating
    0
    Gamer is on a distinguished road

      0  

    Default


    I think these are probably scope issues. I tried the other factory function im working on and got the same JSONlint message. In the console I got "Uncaught SyntaxError: Unexpected token this".

    Code:
    Ext.ux.CarterRemoteCombo = function(config) {
        return new Ext.form.ComboBox(Ext.apply({
        	id: 'mycombo',
    		fieldLabel: 'Locations',
    		displayField: 'name',
    		name: 'list_ids',
    		mode: 'local',
    		triggerAction: 'all',
    		store: new Ext.data.JsonStore({
    			proxy: new Ext.data.HttpProxy({
    				url: 'list.asp',
    				method: 'post'
    			}),
    			autoLoad: true,
    			baseParams: config.baseParams || {Field1: '1', Field2: '2', Field3: '3'},
    			fields: [{name: 'id'}, {name: 'name'}],
    			id: 'id',
    			root: 'Records'
    		})
       }, config));
    };
    Ext.reg('carterremotecombo', Ext.ux.CarterRemoteCombo);
    this is the filler code I was given to test against. not sure if thats gonna make it any easier to answer the question.
    Danger Zone!

  3. #3
    Ext JS Premium Member troseberry's Avatar
    Join Date
    Feb 2010
    Location
    Dayton, OH
    Posts
    277
    Vote Rating
    9
    troseberry will become famous soon enough

      0  

    Default


    Well just looking at the code in your first post there are syntax issues. Particularly in the "listeners" area between the "collapse" and "add" configs. There is no proper closure. And yes there at glance appears that there might be scoping issues. However I at least fixed the closure problems.

    Code:
    Ext.ns('Ext.ux');
    //start of factory function
    Ext.ux.CarterRemoteCombo = function (config) {
        return new Ext.ux.form.ComboBoxAdd(Ext.apply({
            name: 'SiteID',
            fieldLabel: this.name,
            hiddenName: this.name,
            displayField: 'lookupname',
            originalwhere: 'this.name',
            valueField: 'lookupid',
            moegalReturnid: 'this.valueField',
            comboVarname: 'tblbillboard_siteID',
            allowBlank: false,
            forceSelection: true,
            //pageSize:50,
            listWidth: 300,
            triggerAction: 'all',
            typeAhead: true,
            minChars: 3,
            //mode: 'remote', defaults at remote
            lazyInit: false,
            //hideTrigger1: false, combo defaults at false
            //hideTrigger2: false, clear defaults at false
            hideTrigger3: true,
            //search
            //hideTrigger4: false, add defaults at false
            listeners: {
                collapse: function (combo) {
                    if (this.startValue != this.getValue()) {
                        UpdateDependentComboboxStore('this.comboVarname', this.getValue(), 'this.name', 5, 'this.mode');
                        console.log(this.name);
                        console.log(this.getValue());
                    }
                },
                add: function (this) {
                    loadwindow('Add Site', 'includes/table-insert.asp', true, 'tableID=5&refreshType=combo&refreshID=tblbillboard_siteID', false);
                },
                lookup: function () {
                    loadwindow('Search Site', 'includes/table-search.asp', true, 'tableID=5&refreshType=combo&refreshID=tblbillboard_siteID&linktableID=&linkID=' + this.store.baseParams.LinkID, true);
                },
                render: function (this) {
                    this.store.add(new Ext.data.Record({
                        this.valueField: '40',
                        this.displayField: '4000/4001CPA',
                        linkedid: ''
                    }));
                    this.setValue(40);
                    UpdateDependentComboboxStore('this.comvoVarname', 40, 'this.name', 5, 'this.mode');
                }
            },
            store: new Ext.data.JsonStore({
                proxy: new Ext.data.HttpProxy({
                    url: 'includes/get-comboremote.asp',
                    method: 'post'
                }),
                totalProperty: 'RecordCount',
                autoLoad: false,
                baseParams: {
                    linkedid: "",
                    allowNew: "true",
                    allowSearch: "false",
                    table: "tblsite",
                    idname: "this.name",
                    displayfield: "sitename",
                    linkTableID: "",
                    orderby: "this.name asc",
                    where: "this.name",
                    lookupID: 40
                },
                fields: ['this.valueField', 'this.displayField', 'linkedid'],
                id: 'this.valueField',
                root: 'Records',
                listeners: {
                    load: function () {
                        if (this.startValue != '') {
                            if (this.store.find('this.valueField', this.startValue) != '-1') {
                                this.setValue(this.startValue);
                                UpdateDependentComboboxStore('this.comboVarname', this.getValue(), 'this.name', 5, 'this.mode');
                            }
                        }
                    }
                }
            })
        }, config));
    };
    Ext.reg('carterremotecombo', Ext.ux.CarterRemoteCombo);

Similar Threads

  1. [SOLVED] question on factory function
    By moegal in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 11 Aug 2010, 5:44 PM
  2. CRUD Factory
    By mask_hot in forum Community Discussion
    Replies: 4
    Last Post: 4 Mar 2010, 2:05 AM
  3. Ajax.request factory
    By stricte in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 4 Jan 2010, 2:38 PM
  4. Factory Function File Pattern
    By jsakalos in forum Ext 2.x: Help & Discussion
    Replies: 6
    Last Post: 19 Apr 2009, 7:01 AM

Thread Participants: 1