Hello Jnanendra -
My apologies, I should have tested your specific scenario. I too am getting the same behavior you are seeing when setting REFPICK before rendering in edit model.
In troubleshooting a bit further, it appears that after going in to “edit” mode the first time, the custom snippet never gets called to render the field again. Since the renderer isn’t getting called, I can’t think of a way to workaround this other than to setup a listener to listen for cancel and then force a render of that field - although I’m not sure that will work based on what I describe below. Additionally, even when you go out of edit mode without hitting cancel (by just clicking somewhere else on the screen for example), you end up with the hyperlink.
Steps to repro:
- Create page using XML below
- open browser, display dev tools console and open the page specifying an account
- Go in to edit mode, pick a different owner and click-off field
- click cancel
Actual Result - Console Log indicates:
Renderer for OwnerId in mode read
Renderer for OwnerId in mode edit
Expected Result - Console Log indicates
Renderer for OwnerId in mode read (initial page load)
Renderer for OwnerId in mode edit (go to edit mode)
Renderer for OwnerId in mode read (change value and click off field to go back to read)
Renderer for OwnerId in mode read (cancel button)
<skuidpage showsidebar="true" showheader="true" tabtooverride="Account"> <models>
<model id="Account" limit="1" query="true" createrowifnonefound="false" sobject="Account">
<fields>
<field id="Name"/>
<field id="CreatedDate"/>
<field id="OwnerId"/>
<field id="Owner.Name"/>
</fields>
<conditions>
<condition type="param" enclosevalueinquotes="true" operator="=" field="Id" value="id"/>
</conditions>
</model>
</models>
<components>
<pagetitle model="Account">
<maintitle>
<template>{{Name}}</template>
</maintitle>
<subtitle>
<template>{{Model.label}}</template>
</subtitle>
<actions>
<action type="savecancel" window="self">
<models>
<model>Account</model>
</models>
</action>
</actions>
</pagetitle>
<basicfieldeditor showsavecancel="false" showheader="true" model="Account" mode="read">
<columns>
<column width="100%">
<sections>
<section title="Basics">
<fields>
<field id="Name"/>
<field id="OwnerId" type="CUSTOM" snippet="ownerIdRenderer"/>
</fields>
</section>
</sections>
</column>
</columns>
</basicfieldeditor>
</components>
<resources>
<labels/>
<css/>
<javascript>
<jsitem location="inlinesnippet" name="ownerIdRenderer" cachelocation="false">var field = arguments[0],
value = arguments[1],
renderer = skuid.ui.fieldRenderers[field.metadata.displaytype],
mode = field.mode,
$ = skuid.$;
console.log('Renderer for ' + field.id + ' in mode ' + mode);
// if we are not in edit mode
if (mode != 'edit') {
// there is a issue in skuid that does not properly clear out the relationship (__r) field
// when the relationship ID (__c) field gets set to null/empty. For this reason, since in non-edit
// mode below we retrieve a value to display from the relationship field, we will end up with a value in there
// that is incorrect because the relationship id field (__c) is empty. To workaround this, we
// check to see if we have a value in the relationship id field (represented by argument[1]) and if so, force
// an empty string to be displayed.
// TODO: The "__r" not being cleared when "__c" is cleared is expected to be addressed by
// skuid in a future release at which point this code can be simplified.
// we pass true as the third argument so we get the non-encoded version of the text value
var refFieldValue = value ? field.model.getFieldValue(field.row, skuid.utils.getFieldReference(field.id, field.metadata), true) : '';
// one last check to make sure we have something and don't display 'null' on the screen
var refFieldValue = refFieldValue || '';
// build the element using a DIV and adding skuid class to it
field.element.append(skuid.$('&lt;div&gt;').addClass('nx-fieldtext').text(refFieldValue));
}
// if we are in edit mode
else {
// Run standard renderer for the current mode
// (applies to read/edit mode)
field.options.type = 'REFPICK';
renderer[mode](field,value);
}</jsitem>
</javascript>
</resources>
</skuidpage>