Link to home
Create AccountLog in
Avatar of elliottbenzle
elliottbenzle

asked on

Help understanding Ext.form.TextField

I have the below code:
      osemscProfile.textfield = function(fname,pid){
            var fieldname = osemscProfile.textfield+fname;
            var testtext = "Did it work?";
            fieldname = new Ext.form.TextField({
                  fieldLabel:fname
                  ,name:'profile_'+pid
                  ,allowBlank:blank
            });
            return fieldname;
      };


It produces this:
<input type="text" size="20" autocomplete="off" id="ext-comp-1114" name="profile_1" class="x-form-text x-form-field" style="width: 272px; " title="">

I want to set autocomplete to on, but when I add  ,autocomplete:on     above    ,allowBlank:blank
nothing shows up. Also I don't understand where the id, class, style and other attributes are coming from?

The whole page code is attached if that helps. Any insight would be great. Thank you.

Ext.ns('oseMscAddon');
Ext.ns('osemscProfile');
oseMscAddon.profile = function()	{

}

osemscProfile.FileUpload = function(cname,pid,blank)	{

	var FileUpladname = osemscProfile.fileupload+cname;
	FileUpladname = new Ext.form.CompositeField({
		fieldLabel: cname
		,items:[{
    		xtype: 'button'
	    	,text: 'Upload'
	    	,handler: function()	{
	    		if(!uploadImgWin)	{
	    			var uploadImgWin = new Ext.Window({
	    				title: 'Upload File'
	    				,bodyStyle: ''
	    				,width: 300
	    				,autoHeight: true
	    				,modal: true
	    				,items:[{
	    					xtype: 'form'
	    					,ref: 'form'
	    					,fileUpload: true
	    					,height: 100
	    					,border: false
	    					,defaults: {border: false}
	    					,items:[{
	    						layout: 'hbox'
	    						,defaults: {border: false}
	    						,hideLabel: true
	    						,items:[{
	    							xtype:'fileuploadfield'
	    			                ,height: 30
	    			                ,name: 'file'
	    			                ,width: 150
	    			                ,buttonOnly: true
	    				            ,buttonText: 'Browse'
	    					        ,buttonCfg: {
	    				            	width: 100
	    				            }
	    			                ,listeners: {
	    				            	fileselected: function(fb, v){
	    				            		
	    				            		Ext.each(oseMscAddon.pform.findByType('compositefield'), function(item,i,all){
		    				    	    		Ext.each(item.items.items, function(subitem,i,all){
		    				    	    			if(subitem.getXType() == 'textfield' && subitem.id == ('profile_'+pid) && subitem.getValue() != '')	{
		    				    	    				var path = subitem.getValue();
		    				    	    				Ext.Ajax.request({
		    				    	    					url: 'index.php?option=com_osemsc&controller=register',
		    				    	    					params: {task: "action",action:'register.profile.reset','file_path':path}
		    				    	    				});
		    				    	    				subitem.setValue('');
		    						    			}
		    				    				})
		    				    	    	});
	    				            		
	    				            		uploadImgWin.form.getForm().submit({
	    				            			url:'index.php?option=com_osemsc&controller=register',
	    				            			params:{task: "action",action:'register.profile.upload','pid':pid},
	    				            			success:function(form,action)	{
	    				            				var msg = action.result;
	    				            				if(msg.uploaded){
	    				            					Ext.each(oseMscAddon.pform.findByType('compositefield'), function(item,i,all){
	    			    				    	    		Ext.each(item.items.items, function(subitem,i,all){
	    			    				    	    			if(subitem.getXType() == 'textfield' && subitem.id == ('profile_'+pid))	{
	    			    				    	    				subitem.setValue(msg.file_path);
	    			      						    			}
	    			    				    				})
	    			    				    	    	});
	    				            					oseMsc.msg.setAlert(msg.title,msg.content);
	    				            				}	else	{
	    				            					Ext.Msg.alert(msg.title,msg.content);
	    				            				}
	    				            				//uploadImgWin.close();
	    				            			},
	    				            			failure:function(form,action){
	    				            				var msg = action.result;
	    				            				Ext.Msg.alert('Error','Failed!');
	    				            			}
	    				            		});
	    				            	}
	    				            }
	    						},{
	    				    		xtype: 'button'
	    				    	    ,text: 'Reset'
	    				    	    ,handler: function()	{
	    				    	    	Ext.each(oseMscAddon.pform.findByType('compositefield'), function(item,i,all){
	    				    	    		Ext.each(item.items.items, function(subitem,i,all){
	    				    	    			if(subitem.getXType() == 'textfield' && subitem.id == ('profile_'+pid))	{
	    				    	    				var path = subitem.getValue();
	    				    	    				Ext.Ajax.request({
	    				    	    					url: 'index.php?option=com_osemsc&controller=register',
	    				    	    					params: {task: "action",action:'register.profile.reset','file_path':path},

	    				    	    				    success: function(response, opt) {
	    				    	    						var res = Ext.decode(response.responseText);
	    				    	    						oseMsc.msg.setAlert(res.title,res.content);

	    				    	    				    }
	    				    	    				});
	    				    	    				subitem.setValue('');
	    						    			}
	    				    				})
	    				    	    	});
	    				    	    }
	    						}]
	    					}]
	    				}]
	    			})
	    		}

	    		uploadImgWin.show().alignTo(Ext.getBody(),'c-c')
	    	}
    	},{
    		xtype:'textfield'
    		,hidden:true	
        	,id:'profile_'+pid
        	,name:'profile_'+pid
        }]
	});
	return FileUpladname;
};
	
osemscProfile.MS = function(cname,pid,blank)	{

	var MSname = osemscProfile.multiSelect+cname;
	MSname = new Ext.ux.form.MultiSelect({
		fieldLabel: cname
		,id:'profile_'+pid
	    ,name: 'profile_'+pid
	   // ,width: 250
	    ,height: 150
	    ,allowBlank:blank
	    ,store: new Ext.data.Store({
			  proxy: new Ext.data.HttpProxy({
		            url: 'index.php?option=com_osemsc&controller=register'
		            ,method: 'POST'
		      })
	    	,baseParams:{task: "action",action:'register.profile.getOptions',id:pid}
			  ,reader: new Ext.data.JsonReader({
			    root: 'results'
			    ,totalProperty: 'total'
			  },[
			    {name: 'option', type: 'string', mapping: 'option'}
			  ])
			  ,autoLoad:{}
		})
	    ,valueField: 'option'
	    ,displayField: 'option'

	    ,tbar:[{
	        text: 'Reset',
	        handler: function(){
	    		oseMscAddon.pform.findById('profile_'+pid).reset();
	        }
	    }]

	});
	return MSname;
	};

	osemscProfile.textarea = function(fname,pid,blank){
		var fieldname = osemscProfile.textarea+fname;
		fieldname = new Ext.form.TextArea({
			fieldLabel:fname
			,name:'profile_'+pid
			,allowBlank: blank
		});
		return fieldname;
	};

	osemscProfile.combo = function(cname,pid)	{

		var comboname = osemscProfile.combo+cname;
		comboname = new Ext.form.ComboBox({
	  		fieldLabel: cname
	        ,hiddenName: 'profile_'+pid
		    ,typeAhead: true
		    ,triggerAction: 'all'
		    ,lazyRender:true
		    ,mode: 'remote'
		    ,allowBlank:blank
		    ,lastQuery: ''
		    ,store: new Ext.data.Store({
				  proxy: new Ext.data.HttpProxy({
			            url: 'index.php?option=com_osemsc&controller=register'
			            ,method: 'POST'
			      })
		    	,baseParams:{task: "action",action:'register.profile.getOptions',id:pid}
				  ,reader: new Ext.data.JsonReader({
				    root: 'results'
				    ,totalProperty: 'total'
				  },[
				    {name: 'option', type: 'string', mapping: 'option'}
				  ])
				  ,autoLoad:{}
			})

		    ,valueField: 'option'
		    ,displayField: 'option'

	  	});

		return comboname;
	};

	osemscProfile.textfield = function(fname,pid){
		var fieldname = osemscProfile.textfield+fname;
		var testtext = "Did it work?";
		fieldname = new Ext.form.TextField({
			fieldLabel:fname
			,name:'profile_'+pid
			,allowBlank:blank
		});
		return fieldname;
	};

	osemscProfile.radio = function(rname,pid,radioItems){

		var radioname = osemscProfile.radio+rname;
		radioname = new Ext.form.RadioGroup({
		fieldLabel: rname
		,columns: 2
		,name: 'profile_'+pid
		,allowBlank:blank
		,defaults:{xtype:'radio',name:'profile_'+pid}
		,items:radioItems
		});
		return radioname;


	}

	oseMscAddon.profile.prototype = {
		init: function()	{
			var p =new Ext.Panel({
			border: false
	 		,labelWidth: 130
	 		//,layout: 'form'
	 		//,items:oseMscAddon.formtest
			,listeners: {
				render: function(p){

					Ext.Ajax.request({
						url: 'index.php?option=com_osemsc&controller=register',
						params: {task: "action",action:'register.profile.getList'},

					    success: function(response, opt) {
							var res = Ext.decode(response.responseText);
							var results = res.results;
							var aitems = new Array();
							for(i=0; i<results.length; i++)	{
								if(results[i].require > 0)
								{
									blank = false;
								}else{
									blank = true;
								}
								switch (results[i].type)
								{
									case('textfield'):
										aitems[i] = osemscProfile.textfield(results[i].name,results[i].id,blank);
										break;
									case('textarea'):
										aitems[i] = osemscProfile.textarea(results[i].name,results[i].id,blank);
										break;
									case('combo'):
										aitems[i] = osemscProfile.combo(results[i].name,results[i].id,blank);
										break;
									case('radio'):
										aitems[i] = osemscProfile.radio(results[i].name,results[i].id,results[i].params,blank);
										break;
									case('multiselect'):
										aitems[i] = osemscProfile.MS(results[i].name,results[i].id,blank);
										break;
									case('fileuploadfield'):
										aitems[i] = osemscProfile.FileUpload(results[i].name,results[i].id,blank);
										break;	
								}

							}
							oseMscAddon.pform = new Ext.form.FieldSet({
								border: true
								,title: Joomla.JText._('Additional_Information')
								,defaults: {width: 280,msgTarget : 'side'}
						        ,labelWidth: 130
						        ,items: aitems
							});

							p.add(oseMscAddon.pform);
							p.doLayout();
					    }
					});
				}
			}

			})

			return p;
		}
	}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of elliottbenzle
elliottbenzle

ASKER

Thanks Hielo,

That was extremely helpful.