Autocomplete link options based on another link

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • czcpf
    Senior Member
    • Aug 2022
    • 160

    Autocomplete link options based on another link

    Can someone please give me some advise. I have two links in an entity called XrayMachine as shown in the attachment. The parent link is called XrayMachineUseCategory and the child link is called XrayModalityCategory. XrayModalityCategory is a Many-To-One relation with XrayMachineUseCategory.

    After the user selects XrayMachineUseCategory only the XrayModalityCategories that are linked to XrayMachineUseCategory
    (ie. XrayModalityCategory.XrayMachineUseCategoryId = XrayMachineUseCategory.Id) in database should be available in auto-complete.

    Based on other posts in this forum, I was able to make it so that when a user clicks the select to open the modal window of XrayModalityCategory it filters only those that are linked to the selected XrayMachineUseCategory as shown in attached image: XrayModalityCategory Modal Behavior. The behavior in Auto-Complete is also shown in the second image XrayModalityCategory Auto-Complete Behavior. Notice here, when the user types "i" into the select box, the option Intraoral is presented when XrayMachineUseCategory is 'Radiography' even though that XrayModalityCategory is not linked to Radiography. It seems one could use getSelectPrimaryFilterName and return a selectFilterClass but it is not clear to me how said selectFilterClass would know what XrayMachineUseCategory was selected? It's not like getSelectFilters where you can return a dynamic filter object..

    client/custom/src/views/x-ray-machine/fields/x-ray-modality-category.js

    Code:
    define('custom:views/xray-machine/fields/xray-modality-category', ['views/fields/link'], function (Dep) {
    
    return Dep.extend({
    
    createDisabled: true,
    
    getSelectFilters: function () {
    let xrayMachineUseCategoryId = this.model.get('xrayMachineUseCategoryId');
    if (xrayMachineUseCategoryId) {
    
    return {
    'xrayMachineUseCategory': {
    type: 'linkedWith',
    value: xrayMachineUseCategoryId,
    data: {
    type: 'is',
    nameValue: this.model.get('xrayMachineUseCategoryName'),
    },
    }
    };
    }
    
    return null;
    },
    
    getCreateAttributes: function () {
    if (this.model.get('xrayMachineUseCategoryId')) {
    return {
    xrayMachineUseCategoryId: this.model.get('xrayMachineUseCategoryId'),
    xrayMachineUseCategoryName: this.model.get('xrayMachineUseCategoryName'),
    }
    }
    
    return null;
    },
    });
    });​
    ​
Working...