Relate field in custom view

Hi,

We have created a custom view / dashlet which is loaded on the side of our create view to perform checks and give suggestions when creating a record of a custom module. 

In this dashlet I want to add a relate field so I can adjust my logic based on the selected account.

In my hbs file I now have an input field:

<input type="text" name="account-id" data-action="lookup-on-change" autocomplete="off">

But this is a simple input text field and users have to copy / paste an id into the field. 

Is it possible to use a standard relate field component in my custom component?
Something like: 

<sugar-relate type="account" on-change="xyz">

Or maybe from the javascript side, something like:

app.view.createView({
context: this.context,
type: 'relate',
module: this.module,
layout: this,
model: model,
nopreview: true // hide preview button
});

Any help or links to documentation would be appreciated.

Parents
  • Looking through the Sugar Core files I got something kind of working. Here is a sample of the code, but I will update it once it is fully operational:

    this.model.set({
    related_custom_account_name: this.lookupAccountName,
    related_custom_account_id: this.lookupAccountId
    });

    this.model.on('change:related_custom_account_name', function() { console.log('Changing name!'); }, this);
    this.model.on('change:related_custom_account_id', function() { console.log('Changing id!'); }, this);

    let field = app.view.createField({
    def: {
    type: 'relate',
    module: 'Accounts',
    name: 'related_custom_account_name',
    rname: 'name',
    id_name: 'related_custom_account_id',
    },
    view: this,
    viewName: 'edit',
    });

    field.render();
    //field.setValue = _.bind(this.setValue, this);
    this.$('#relate-field-container').append(field.$el);

Reply
  • Looking through the Sugar Core files I got something kind of working. Here is a sample of the code, but I will update it once it is fully operational:

    this.model.set({
    related_custom_account_name: this.lookupAccountName,
    related_custom_account_id: this.lookupAccountId
    });

    this.model.on('change:related_custom_account_name', function() { console.log('Changing name!'); }, this);
    this.model.on('change:related_custom_account_id', function() { console.log('Changing id!'); }, this);

    let field = app.view.createField({
    def: {
    type: 'relate',
    module: 'Accounts',
    name: 'related_custom_account_name',
    rname: 'name',
    id_name: 'related_custom_account_id',
    },
    view: this,
    viewName: 'edit',
    });

    field.render();
    //field.setValue = _.bind(this.setValue, this);
    this.$('#relate-field-container').append(field.$el);

Children
No Data