Keystone-classic: How to add clickable link on admin side in keystonejs

Created on 4 Apr 2018  ·  2Comments  ·  Source: keystonejs/keystone-classic

In keystonejs, I want to add a link on admin side. lets say I have type string or type url as shown, but both show text box on admin side

link: { type: String}
url: {type: Types.Url}

What I am achieving is, If I have product model and by clicking on that link (on admin side) I want to open public link of that particular product in new tab on browser.

question

Most helpful comment

Thanks @1337cookie. I changed this a little bit in case someone wants to do a virtual field (not making the field persistent in the DB).

Brand.add({
    name: { type: String, required: true },
    url: { type: Types.Url, noedit: true },
});

// Use a virtual field to avoid making the field persistent
Brand.schema.virtual('urlVirtual').get(function(){
    return "www.google.com/search?q=" + this.some_prop;
});

// copy virtual field at schema run time.
Brand.schema.post('init', function(){
    this.url = this.urlVirtual;
});

All 2 comments

I've done something similar you can use.
Edited for clarity:

Brand.add({
    name: { type: String, required: true },
    url:{ type: Types.Url, watch: 'name', value: makeURL, noedit: true}
});
function makeURL() {
    return "www.google.com/search?q=" + this.name;
};

Thanks @1337cookie. I changed this a little bit in case someone wants to do a virtual field (not making the field persistent in the DB).

Brand.add({
    name: { type: String, required: true },
    url: { type: Types.Url, noedit: true },
});

// Use a virtual field to avoid making the field persistent
Brand.schema.virtual('urlVirtual').get(function(){
    return "www.google.com/search?q=" + this.some_prop;
});

// copy virtual field at schema run time.
Brand.schema.post('init', function(){
    this.url = this.urlVirtual;
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jacqueslareau picture jacqueslareau  ·  5Comments

zhdan88vadim picture zhdan88vadim  ·  5Comments

sorryididntmeantto picture sorryididntmeantto  ·  3Comments

rigalpatel001 picture rigalpatel001  ·  5Comments

koenoe picture koenoe  ·  4Comments