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.
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;
});
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).