field renderer display a field twice

  • 1
  • Problem
  • Updated 3 years ago
  • Not a Problem
Hi,

I have a custom field renderer to populate a picklist, 
I have gone through this post : https://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](field,value);
}



Please find below XML for whole Page :

<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="false" showheader="true" theme="Modern">   <models>
      <model id="Account" limit="1" query="true" createrowifnonefound="false" adapter="" type="" sobject="Account">
         <fields>
            <field id="Name"/>
            <field id="Id"/>
            <field id="RelatedAddress__c"/>
            <field id="RelatedAddress__r.Name"/>
            <field id="RelatedAddress__r.Addr2__c"/>
            <field id="RelatedAddress__r.Addr3__c"/>
            <field id="RelatedAddress__r.Address_Type__c"/>
         </fields>
         <conditions>
            <condition type="param" value="id" field="Id" operator="=" enclosevalueinquotes="true" novaluebehavior="deactivate"/>
         </conditions>
         <actions/>
      </model>
      <model id="Address" limit="" query="true" createrowifnonefound="true" adapter="" type="" sobject="Address__c" doclone="">
         <fields>
            <field id="Name"/>
            <field id="Addr2__c"/>
            <field id="Addr3__c"/>
            <field id="Address_Name__c"/>
            <field id="Address_Type__c"/>
            <field id="City__c"/>
            <field id="County__c"/>
            <field id="Postal_Code__c"/>
            <field id="Primary__c"/>
            <field id="Id"/>
            <field id="AddressList_ui" uionly="true" displaytype="PICKLIST" label="Addresses" helptext="List of Addresses">
               <picklistentries/>
            </field>
            <field id="selectedAddressID_ui" uionly="true" displaytype="TEXT" label="Selected Address ID"/>
         </fields>
         <conditions>
            <condition type="modelmerge" value="" field="Account__c" operator="=" model="Account" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="deactivate" state=""/>
         </conditions>
         <actions>
            <action>
               <actions>
                  <action type="custom" snippet="selAddrModelUtil"/>
                  <action type="setCondition" model="selectedAddress" condition="selectedAddressIDCondition" value="{{selectedAddressID_ui}}"/>
                  <action type="requeryModel" model="selectedAddress" behavior="standard"/>
               </actions>
               <events>
                  <event>row.created</event>
                  <event>row.updated</event>
               </events>
               <fields>
                  <field>AddressList_ui</field>
               </fields>
            </action>
         </actions>
      </model>
      <model id="selectedAddress" limit="1" query="false" createrowifnonefound="true" adapter="" type="" sobject="Address__c">
         <fields>
            <field id="Name"/>
            <field id="Addr2__c"/>
            <field id="Addr3__c"/>
            <field id="Address_Name__c"/>
            <field id="Address_Type__c"/>
            <field id="City__c"/>
            <field id="County__c"/>
            <field id="Primary__c"/>
            <field id="Postal_Code__c"/>
            <field id="Id"/>
            <field id="State__c"/>
         </fields>
         <conditions>
            <condition type="fieldvalue" value="" enclosevalueinquotes="true" field="Id" state="filterableoff" inactive="true" name="selectedAddressIDCondition"/>
         </conditions>
         <actions/>
      </model>
   </models>
   <components>
      <grid uniqueid="sk-glPwC-158">
         <divisions>
            <division behavior="flex" minwidth="100px" ratio="1">
               <components>
                  <pagetitle model="Address" uniqueid="sk-gpkGQ-302">
                     <actions/>
                     <maintitle>Address to Pick</maintitle>
                  </pagetitle>
                  <basicfieldeditor showheader="true" showsavecancel="false" showerrorsinline="true" model="Address" buttonposition="" uniqueid="sk-glUM9-167" mode="edit" layout="">
                     <columns>
                        <column width="65%">
                           <sections>
                              <section title="" collapsible="no" showheader="false">
                                 <fields>
                                    <field id="AddressList_ui" showhelp="true" valuehalign="" type="CUSTOM" snippet="populatePickList">
                                       <renderconditions logictype="and" onhidedatabehavior="keep"/>
                                       <enableconditions logictype="and"/>
                                    </field>
                                 </fields>
                              </section>
                           </sections>
                        </column>
                     </columns>
                     <renderconditions logictype="and"/>
                  </basicfieldeditor>
               </components>
            </division>
            <division behavior="flex" verticalalign="top" minwidth="100px" ratio="1">
               <components>
                  <pagetitle model="Address" uniqueid="sk-gq8qx-324">
                     <maintitle>Selected Address Details</maintitle>
                     <actions/>
                  </pagetitle>
                  <basicfieldeditor showheader="true" showsavecancel="false" showerrorsinline="true" model="selectedAddress" buttonposition="" uniqueid="sk-goQ48-260" mode="readonly">
                     <columns>
                        <column width="100%">
                           <sections>
                              <section title="Address Details" collapsible="no" showheader="false">
                                 <fields>
                                    <field id="Name"/>
                                    <field id="Addr2__c"/>
                                    <field id="City__c"/>
                                    <field id="State__c" valuehalign="" type=""/>
                                    <field id="County__c"/>
                                    <field id="Postal_Code__c"/>
                                    <field id="Primary__c"/>
                                 </fields>
                              </section>
                           </sections>
                        </column>
                     </columns>
                     <renderconditions logictype="and"/>
                  </basicfieldeditor>
               </components>
            </division>
            <division behavior="flex" verticalalign="top" minwidth="100px" ratio="1">
               <components/>
            </division>
         </divisions>
         <styles>
            <styleitem type="background" bgtype="none"/>
         </styles>
      </grid>
   </components>
   <resources>
      <labels/>
      <javascript>
         <jsitem location="inlinesnippet" name="populatePickList" cachelocation="false">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](field,value);
}


</jsitem>
         <jsitem location="inlinesnippet" name="selAddrModelUtil" cachelocation="false">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)
                            });
    
}</jsitem>
      </javascript>
      <css/>
   </resources>
   <styles>
      <styleitem type="background" bgtype="none"/>
   </styles>
</skuidpage>
Photo of KVin

KVin

  • 1,158 Points 1k badge 2x thumb

Posted 3 years ago

  • 1
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
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.
Photo of KVin

KVin

  • 1,158 Points 1k badge 2x thumb
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!


 
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
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.
Photo of KVin

KVin

  • 1,158 Points 1k badge 2x thumb
Thanks Matt. 
I better keep some values on the picklist then.