Can we use ListGridItem in DynamicForm

I need to use Listgrid in Dynamic Form in my application. I have defined new class at center place.

isc.defineClass("NRSListGrid","ListGrid").addProperties({
   			 alternateRecordStyles:true, showHeader:false, width:"65%", leaveScrollbarGap:false,
		    fields:[
		        {name:"name"}
		    ]
	});

I have used the following code in view

this.logRolesList =	isc.NRSListGrid.create({
				        ID:"logRolesList",showAllRecords:true
				    });		

userPreferencesForm = isc.DynamicForm.create({id:"userPreferencesForm",wrapItemTitles:false,
				 autoDraw:false,numCols:4,canFocus:true,autoFocus:true,height:"100%",width:"100%",colWidths:["30%","20%","25%","25%"],

				fields:[{name:"lastName", type:"text",title:"Last Name *", titleOrientation:"left",required:true,defaultValue:""
						}, 
						{name:"firstName", type:"text", title:"First Name *", 		titleOrientation:"left",defaultValue:"",required:true,startRow:"true"
						},
						{name:"logRolesListGrid",title:"Logical Role",type:"logRolesList", rowSpan:"5",height:"120",disabled:"true"
						},
						{name:"submitButton", type:"button", title:"Update Profile", align:"center", colSpan:"4"
						 },
					    ]//fields
		});//form

I need to populate grid object present inside form after fetching data from server. I have js Array which need to be set in grid.
Can you tell me functions/way to perform add/remove methods on grid[part of dynamic form]?
Thanks in advance.
Vikram

Hi vikram,

Not sure what you’re asking - you were provided a working example before (this post) - a ListGrid used as part of a CanvasItem supports it’s normal APIs, eg, setData() to change the dataset.

Thanks for reply.
I have overriden setValue method defined in example in order to set/handle single and array.

setValue : function (newValue) {
	        if (this.canvas != null && !this.userSetValue) {
	            var record = this.canvas.data.find(this.dataFieldName, newValue);
	            if (record) this.canvas.selection.selectSingle(record)
	            else {
		            for(i=0;i<newValue.length;i++){
		                this.canvas.data.add({logRoleName:newValue[i]},i);
		            }
	                this.canvas.selection.deselectAll();
	            }
	        }
	        return this.Super("setValue", [newValue]);
	    }
  1. Now I need to get all values present in this ListGridItem.
  2. I need to remove value/values from it.[not drag & drop]
    I have to override some methods or built in function is there. Please update me.

Thanks

Hi Vikram,

Have you discovered the SmartClient Reference documentation? canvas.data is an Array - you already figured out add(), now you need to use remove(), get(), etc

I m using this component in my dynamic form. It is working perfectly as per requirement.
But now I am facing a new issue with Esc key. I have observed in smart client (Especially in IE ) that on single Esc key press SM set default value in current form item and double Esc key press set default value of all items of the form.
I have overriden setValue() method for my listgrid item which is being used in dynamic form along with other items like textitem.
So whenever user press Esc key two times, default handler of SM( as per my understanding) try to call setValue method of each item. As you can see above setValue method of ListgridItem is trying to add some value(default), so as a result the contents of the grid is again appended with same values.
How can I handle Esc key in my ListGridItem?
I want to do nothing on Esc key press for this customized components.

Thanks in advance,
Vikram

isc.ClassFactory.defineClass("ListGridItem", "CanvasItem");

isc.ListGridItem.addProperties({
// default sizing / formatting properties, etc - tweak as required

// this is going to be an editable data item
shouldSaveValue:true,width:150,

// Override init to create the ListGrid with the user can use to set the value.
init:function () {
this.canvas = isc.ListGrid.create({
    autoDraw:false,showHeader:false,leaveScrollbarGap:false,
    // pointer back to the item
    item:this,
    fields:[{name:this.dataFieldName}],
    data:this.listData,canHover:true,
    selectionType:"single", 
    // On click store the selection as the item value
    recordClick:"this.updateItem()",
    // On drop ensure the newly dropped option is the current item value
    recordDrop : function () {
	this.Super("recordDrop", arguments);
	this.updateItem();
    },
    updateItem : function () {
	// Simple mechanism to notify the item not to modify the Grid's selection
	// as part of setValue()
	this.item.userSetValue = true;
	var record = this.getSelectedRecord();
	if (record == null) this.item.clearValue();
	else this.item.setValue(record[this.item.dataFieldName]);

	delete this.item.userSetValue;
    }
});
return this.Super("init", arguments);
},

// Override setValue to update the ListGrid selection
setValue : function (newValue) {
    try{
	if (this.canvas != null && !this.userSetValue) {
	    var record = this.canvas.data.find(this.dataFieldName, newValue);
	    if (record) this.canvas.selection.selectSingle(record)
	    else {
		    for(i=0;i<newValue.length;i++){
				this.canvas.data.add({logRoleName:newValue[i]},i);
		    }
		this.canvas.selection.deselectAll();
	    }
	}
	return this.Super("setValue", [newValue]);
	}catch(e){
		alert(e.message + ":" + e.name);
		sipIxLogger.error(e.message + ":" + e.name);
	} 	    
}

Dynamic Form

this.userForms = isc.DynamicForm.create({id:"userMgmtForm",
		 autoDraw:false,numCols:4,rowSpan:9,canFocus:true,overflow:"visible",autoFocus:true,

		fields:[{name:"lastName", type:"textitem",title:"Last Name"+mandFieldSym, height:gsmaFormItemHeightVal, bawrapTitle:false,titleOrientation:"left",required:true,defaultValue:"",changed:function(form, item, value){
						myobj.populateFullName();
					},length:63
				}, 
				{name:"neuStatus", type:"select", title:"Status"+mandFieldSym,titleOrientation:"left",defaultValue:"Active",height:gsmaFormItemHeightVal,required:true,
					valueMap : {
				    "Active" : "Active",
				    "Inactive" : "Inactive"
				}						
				},
				{name:"firstName", type:"text", title:"First Name"+mandFieldSym, height:gsmaFormItemHeightVal,wrapTitle:false,titleOrientation:"left",defaultValue:"",required:true,startRow:"true",changed:function(form, item, value){
						myobj.populateFullName();
					},length:63
				},
				{name:"carList",title:"Logical Roles",type:"ListGridItem",height:"135",dataFieldName:"logRoleName",rowSpan:"5",width:"145"
				},	
			    ]//fields
});//form

You can override bodyKeyPress on the ListGrid to customize the key handling.

My Observation : I have observed in smart client (Especially in IE ) that on single Esc key press SM set default value in current form item and double Esc key press set default value of all items of the form.

Can you tell us more about this behavior?

Internet explorer has a native behavior whereby if you click “Escape” when focused in a text item in an HTML form, the text item is reset to its previous value - or clicking escape twice will reset the entire form (as if the user had clicked a <input type=“reset”> element).

You can reproduce this behavior without loading SmartClient on a very simple HTML form like this:

<form name=form1>
<input type=text name=item1>
<input type=text name=item2>
</form>

The only difference in behavior with DynamicForms is that we intercept the reset event and ensure that the appropriate SmartClient APIs are called to reset the items’ values - so you’ll actually see a call to resetValues() when the user hits the escape key twice.

Thanks a lot for this information.

My requirement is that I want do nothing when user clicks “Escape” i.e. don’t want to reset value in dynamic form. This is achieved by overridding resetValues() function.

this.userForms = isc.DynamicForm.create({id:"userMgmtForm",
		 autoDraw:false,numCols:4,rowSpan:9,canFocus:true,overflow:"visible",autoFocus:true,

		fields:[{name:"lastName", type:"textitem",title:"Last Name"+mandFieldSym, height:gsmaFormItemHeightVal, bawrapTitle:false,titleOrientation:"left",required:true,defaultValue:"",changed:function(form, item, value){
						myobj.populateFullName();
					},length:63
				}, 
				{name:"neuStatus", type:"select", title:"Status"+mandFieldSym,titleOrientation:"left",defaultValue:"Active",height:gsmaFormItemHeightVal,required:true,
					valueMap : {
				    "Active" : "Active",
				    "Inactive" : "Inactive"
				}						
				},
				{name:"firstName", type:"text", title:"First Name"+mandFieldSym, height:gsmaFormItemHeightVal,wrapTitle:false,titleOrientation:"left",defaultValue:"",required:true,startRow:"true",changed:function(form, item, value){
						myobj.populateFullName();
					},length:63
				},
				{name:"carList",title:"Logical Roles",type:"ListGridItem",height:"135",dataFieldName:"logRoleName",rowSpan:"5",width:"145"
				},	
			    ]//fields
                                          ,resetValues():function()
                                          {
			    }
});//form

But I have also reset button to reset this dynamic form.

reset:function(){
	this.userForms.reset();
     }

But by overriding resetValues() function, reset functionality stops working.

Can you tell me how I can achieve these requirements

  1. Do nothing on Escape click.
  2. Reset form fields on Reset button click.

Vikram.

For your resetValues() override, call Super() to invoke the default behavior if and only if you are being called by your own Reset button. Just pass a special parameter to disambiguate the two situations.