field renderer display a field twice

Hi,

I have a custom field renderer to populate a picklist,
I have gone through this post : http://community.skuid.com/skuid/topics/field_rendering_twice

I am not actually doing any update in field renderer snippet but in other snippet which I am running on a model action.

any one has an idea why this is happening ?

Here is my field renderer snippet :

var field = arguments[0], value = arguments[1],
$ = skuid.$;

var addressModel = skuid.$M(‘Address’);
var addrRows = addressModel.getRows();

console.log('field = ',field);
console.log('value = ',value);

var picklistEntries = field.metadata.picklistEntries;

console.log('addresses ==== ',addrRows);

picklistEntries.length = 0;

$.each(addrRows, function(){

picklistEntries.push(
    { 
        value: this.Name+this.Id, 
        label: this.Primary__c ? "Primary Address-"+this.Name : this.Name, 
        defaultValue: this.Primary__c ? true : false, 
        active: true 
        
    });  //add Name field i.e. Address Line-1 Field Value as pick list entry
        });

console.log(‘picklistEntries ===’,picklistEntries);
if(picklistEntries.length){
skuid.ui.fieldRenderers[field.metadata.displaytype]field.mode;
}

Please find below XML for whole Page :













































row.created
row.updated


AddressList_ui































Address to Pick























Selected Address Details




































var field = arguments[0],
value = arguments[1],
$ = skuid.$;

var addressModel = skuid.$M(‘Address’);
var addrRows = addressModel.getRows();

console.log('field = ',field);
console.log('value = ',value);

var picklistEntries = field.metadata.picklistEntries;

console.log('addresses ==== ',addrRows);

picklistEntries.length = 0;

$.each(addrRows, function(){

picklistEntries.push(
    { 
        value: this.Name+this.Id, 
        label: this.Primary__c ? "Primary Address-"+this.Name : this.Name, 
        defaultValue: this.Primary__c ? true : false, 
        active: true 
        
    });  //add Name field i.e. Address Line-1 Field Value as pick list entry
        });

console.log(‘picklistEntries ===’,picklistEntries);
if(picklistEntries.length){
skuid.ui.fieldRenderers[field.metadata.displaytype]field.mode;
}

var params = arguments[0], $ = skuid.$;

var selAddrModel = skuid.$M(‘Address’);
var selAddrRow = selAddrModel.getFirstRow(); //selectedAddressID_ui

var pickListValue = selAddrModel.getFieldValue(selAddrRow,‘AddressList_ui’);

console.log('FROM UTIL pickListValue = ',pickListValue);
console.log('pickListValue.substr(pickListValue.length-18) ====== ',pickListValue.substr(pickListValue.length-18));
if(pickListValue){
selAddrModel.updateRow(selAddrRow,
{
selectedAddressID_ui : pickListValue.substr(pickListValue.length-18)
});

}






KVin,

Is it only that field, or is it every field in the field editor? Check your model and see if it has more than one row. The field editor will duplicate itself for each row in the model.

The Key thing from your response " The field editor will duplicate itself for each row in the model "  - that is what was happening .

I was trying to minimize the no# of models on the page, hence i have created this Ui-Only field on Address__c model, where I get more than one address in most of the cases, so when I use this for field editor , it is showing #no of times of rows it get.


So I have created a separate dummy model , with this ui-only pick-list field and populating this field with the address records received (with Address-line-1 only).

But here, to clear the picklist array , I was doing this :

LINE-1 : var picklistEntries = field.metadata.picklistEntries;

LINE 2:  picklistEntries.length = 0;    // to clear 


here the issue is : if do not create any picklist entry on ui-only field definition on model, the LINE-1 above always get null and line 2 throws error saying cannot set length property of undefined/null.

so I had to create some dummy entry "Test-1’ on ui-only picklist field. 


Any pointers on this Matt ?

Thanks for your help!


 

Yes. I just always create some standard values on the picklist. It’s a good failsafe if the standard renderer runs for some reason instead of your custom renderer, and it takes care of your null.length issue.

Thanks Matt. 
I better keep some values on the picklist then.