Filter link field values
Collapse
X
-
I am not really sure why you need such filter but i am happy to help, so folow steps below:
1 - this is the content of the field (contact) i am assuming the name of the field is contact otherwise you need to change the name to the correct name
Code:define('custom:views/solicitation/fields/contact', 'views/fields/link', function (Dep) { return Dep.extend({ getSelectFilters: function () { if (this.model.get('contactId')) { return { 'name': { type: 'equals', attribute: 'name', value: this.model.get('contactName'), data: { type: 'equals', nameValue: this.model.get('contactName') } } }; } }, getCreateAttributes: function () { if (this.model.get('contactId')) { return { id: this.model.get('contactId'), name: this.model.get('contactName') } } } }); });
Code:{ "fields": { "contact": { "type": "link", "view": "custom:views/solicitation/fields/contact" } } }
This should do the trick but remember that this filter will only work if the field contact has a value otherwise the list will be for all contacts.
PS: The reason why we used name because ID is not accessible from the UI for security reason, so name should do the trick.
Hope this helpsLeave a comment:
-
I think I have to extend the field (link) not select-record.
I replaced and modified the getSelectFilters function but it still doesn't workLeave a comment:
-
Filter link field values
In the "Call" entity, I created a "contact" field.
This field is linked to the "Contact" entity.
Currently, when I click on the select button, I open the modal window that lists all the contacts of the "Contact" entity :
But I would like, when I click on the select button of the field, to open the modal select-record window, already filtering on the name entered in the contact field (if it is empty, the window lists all the contacts as at present) like this :
I created a custom view select-record.js, called in Contact.json.
Looking at the forum, I tried to set up two functions to perform this filter based on the "contact" field of the entity Call.
getSelectFilters: function () {
let userName = this.model.get('contactId');
if (userName) {
return {
contact': {
type: 'equals',
value: userName,
data: {
type: 'is',
nameValue: this.model.get('contactName'),
},
}
};
}
return null;
},
getCreateAttributes: function () {
if (this.model.get('contactId')) {
return {
contactId: this.model.get('contactId'),
contactName: this.model.get('contactName'),
}
}
return null;
},
But it doesn't work, no filter is applied. Do you have a clue?Tags: None
Leave a comment: