Duplicates within rows, 5.8 Sandbox

edited December 4, 2017 in Questions
Just doing some sandbox testing with 5.8 and I can't figure out why I'm getting duplicate text fields within a single row (see attached). There is some javascript running in the background to make this work, which is now creating a duplicate entry for 2 separate fields within one row. When I hit save it executes properly and only saves one record, but obviously I don't want users getting confused.

image

The snippet for departure airport looks like this:

(function(skuid){ var $ = skuid.$,
departAirportFieldReference = 'stack__Depart__r',
departAirportFieldId = 'stack__Depart__c',
arriveAirportFieldName = 'stack__Arrive__r',
arriveAirportFieldId = 'stack__Arrive__c',
sectorNumberFieldName = 'stack__SecNum__c';



skuid.snippet.registerSnippet('fromAirportRenderer', function () {
var field = arguments[0],
//value = arguments[1];
value = field.row[departAirportFieldReference] !== undefined ? field.row[departAirportFieldReference].Name : null;

if (field.mode == 'read') {
//This just outputs what the standard Skuid control would output anyway, since we require no special behavour for rows that are not being edited.
skuid.ui.fieldRenderers.REFERENCE.read(field, value);
}
else {

var referenceFieldId = field.metadata.rel;

//var modelContext = getModelContext(field);

var modelContext = getModelContext(field),
items = modelContext.items;

//If depart airport is empty && this is a new row (i.e. there is no existing value, and no rendered item matching the Id of the current row)
if(items.length > 0 && value === null) {
var prevRow = items[items.length - 1].row,
prevId = prevRow[arriveAirportFieldName] !== undefined ? prevRow[arriveAirportFieldName].Id : null,
prevLabel = prevRow[arriveAirportFieldName] !== undefined ? prevRow[arriveAirportFieldName].stack__apName__c : null;

var modifications = {};
modifications[field.id] = prevId;
modifications[referenceFieldId] = {Id: prevId, Name: prevLabel};
value = modifications[referenceFieldId].Name;


field.model.updateRow(
field.row,
modifications
);
}

new fieldChangeListener(field, function(changes){ 
if(field.row[departAirportFieldReference])
field.element.find('input').val(field.row[departAirportFieldReference].Name);
});

skuid.ui.fieldRenderers.REFERENCE.edit(field, value);
}
});

Comments

  • Zach McElrathZach McElrath Principal Software Engineer Chattanooga, TN 💎💎💎
    edited March 2, 2017
    Hi Greg,

    Please take a look at this community post for an explanation of why this is happening:

    https://community.skuidify.com/skuid/topics/upgraded-to-summer-ga-and-this-line-now-prevents-a-skuid...

    To avoid this, you'll need to change this line:

    field.model.updateRow(
       field.row,
       modifications
    );

    to this:

    field.model.updateRow(
       field.row,
       modifications,
       { initiatorId: field._GUID }
    );





  • edited December 18, 2014
    Check out the last comment by Zach in this post : https://community.skuidify.com/skuid/topics/upgraded-to-summer-ga-and-this-line-now-prevents-a-skuid... the short answer is that "updateRow" is going to cause your field to show up without having to call "skuid.ui.fieldRenderers.REFERENCE.edit(field, value);" so therefore it shows up twice. Check out Zach's answer about how to avoid this.
  • edited December 18, 2014
    Ha Zach beat me by 4 seconds...
  • edited December 4, 2017
    Thanks guys, working like a charm.

    Does the comment about things being more in sync in summer 14 mean that there will be less of a requirement for listeners to hear changes in models?

    (My apologies if this was covered in the recent developer preview - I wan't able to attend that one, it was a choice between customer demo or skuid preview and the customer demo won!)
  • Zach McElrathZach McElrath Principal Software Engineer Chattanooga, TN 💎💎💎
    edited March 2, 2017
    Greg, yes that's the idea --- with this internal change, and the introduction of the Action Framework, we're trying to cut out a lot of places where it takes JavaScript to keep Model data and Components in sync.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!