Is there a way to selectively override/remove a lookup field's link?

  • 3
  • Question
  • Updated 2 years ago
  • Answered
I know I can override a "view" link globally or for profiles or record types, but can I do it selectively (or remove the link entirely) for an editable lookup field in Skuid? I want users to be able to set values in the lookup field, but NOT have the values in the field be clickable (or, at the very least, be able to override the link so I can take them somewhere else). I don't see how to do that with the settings for a lookup field.
Photo of Peter Bender

Peter Bender, Champion

  • 6,266 Points 5k badge 2x thumb

Posted 6 years ago

  • 3
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,530 Points 10k badge 2x thumb
Official Response
Hi Peter,

Unfortunately there's no way to do that "Out of the box". However, this custom field renderer snippet should do the trick.



var field = arguments[0],
value = arguments[1];

if (field.mode === 'read') {
field.element.append(skuid.$('<div>').addClass('nx-fieldtext').text(field.model.getFieldValue(field.row,skuid.utils.getFieldReference(field.id,field.metadata))));
} else {
skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value);
}
Photo of Peter Bender

Peter Bender, Champion

  • 6,266 Points 5k badge 2x thumb
Awesome - works like a charm to remove links from the field in read mode. Thanks!
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,530 Points 10k badge 2x thumb
Just wanted to point out for other people referencing this thread. This technique only works for fields of type REFERENCE. Not for any other field type. If you want to remove links on name fields of type STRING, you can use a template component with three curly braces around name like this: {{{Name}}}.
Photo of ktyler

ktyler

  • 9,254 Points 5k badge 2x thumb
Ben, This works fine and gives an autocomplete... is there a way to have it give a dropdown for a picklist.... I tried
 field.element.append(skuid.$('<div>').addClass('nx-field editable') .text(field.model.getFieldValue(field.row,skuid.utils.getFieldReference(field.id,field.metadata))));
but that still gives a autocomplete

Photo of Gyan

Gyan

  • 1,420 Points 1k badge 2x thumb
Hi Ktyler, 

My requirement is same as yours. I was wondering if you found the way around to get the pick list on edit mode and get rid of hyperlink on read mode.

A slight change on above code works ( see below) unless you  'edit and then cancel the record'  if you do edit and cancel the hyperlink reappears...):


var field = arguments[0],

    value = arguments[1];



if (field.mode === 'read') {


    field.element.append(skuid.$('<div>').addClass('nx-fieldtext').text(field.model.getFieldValue(field.row,skuid.utils.getFieldReference(field.id,field.metadata))));


} else {

    //Just add this line to get pick list on edit mode
    field.options.type = 'REFPICK';

    skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value);


}



Thanks!

-Jnanendra 
(Edited)
Photo of Peter Bender

Peter Bender, Champion

  • 6,266 Points 5k badge 2x thumb
I, too, need to remove the hyperlink when a lookup field (rendered as a picklist) is in read mode, but Jnanendra's sample doesn't seem to do anything for me. Anyone else get his sample to work? Or is there a better way now?
(Edited)
Photo of Tami Lust

Tami Lust

  • 5,326 Points 5k badge 2x thumb
I am trying to remove the hyperlink from the last name when the mode is "Read with inline-editing". I have tried the above code with no avail. Any help would be greatly appreciated.

Below is the current code I have been playing with.

var field = arguments[0],

    value = arguments[1];



if (field.mode === 'read') {


    field.element.append(skuid.$('<div>').addClass('nx-fieldtext').text(LastName.Contacts.getFieldValue(field.row,skuid.utils.getFieldReference(field.id,field.metadata))));


} else {


    skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value);


}
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,148 Points 20k badge 2x thumb
Here is the code that will do what you need.  IE turn the link off for any field direclty on the object that salesforce generally renders as a link (First Name, Last Name, Email, etc), but still allows you to edit the field. 

var field = arguments[0],    value = arguments[1];
if (field.mode === 'read') {
    field.element.append(skuid.$('<div>').addClass('nx-fieldtext').text(value));
} else {
    skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value);
}
Note.  If you are trying to do this on a reference field,  use Ben's approach above. 
Photo of Tami Lust

Tami Lust

  • 5,326 Points 5k badge 2x thumb
Hi Rob! 

Thank you for such a quick reply.

This may be a stupid question but are there changes that I have to make to the above code? I ask because the pesky links remain. What you say this is for is exactly what I need with the exception of email not being a link. I only want the first name and last name to not render as links. As a note the first name and last name are strings.
Photo of Tami Lust

Tami Lust

  • 5,326 Points 5k badge 2x thumb
I just figured it out. Your code works perfect just as is. I created the resource as an in-line snippet. With that I change the field renderer to "custom (run snippet)" only on the fields that I want this script to change. Thank you!
Photo of Ivan

Ivan

  • 152 Points 100 badge 2x thumb
This helped me. I had to make a few modifications to it though, figured I'd share.

We had two problems. 1) A blank value renders as 'null' in view mode, not a blank string. 2) A URL field is not editable. Neither was a difficult fix, but hopefully this will help someone. Code below.

var field = arguments[0],
    value = arguments[1];
    
    if(value === null){
        value = '';
    }
    
if (field.mode === 'read') {
    field.element.append(skuid.$('<div>').addClass('nx-fieldtext').text(value));
} else {
    
    // If display type is URL convert that to STRING
    var displaytype = field.metadata.displaytype;
    displaytype = (displaytype === 'URL') ? 'STRING' : displaytype;
    
    skuid.ui.fieldRenderers[displaytype][field.mode](field,value);
}
Photo of ns

ns

  • 1,822 Points 1k badge 2x thumb
Hello, When I use this, the ampersend gets rewritten as shown in this example:

"Affordable Gadgets &amp; Additions".

This field is the Account Name and is a STRING. Any ideas how to get this from happenning on view? Exporting the record shows normaly btw.