Stop text input for item property in relationship grid

オフライン

Hello,

Is it possible to stop users from selecting an item for a item property using text input in something like the part number property of the product model relationship item? I've added a filter to the OnSearchDialog event of the property to limit the choices, but since it only triggers when the … button is used to open a dialog, I can still input any part number through text.

Is there any way to stop this text input or do I have to make a method that checks the property OnCellChange to verify the selected value?

/Rick

  • Hi Rick,

    To build off of Angela's answer, the samples in that blog post were written in regards to updating the type-ahead for an item property in a form. Most of the code will be the same to those samples, but you will need to take a slightly different approach to get the same functionality in the relationships grid.

    Getting this to work inside of a relationship grid is a little tricky. You'll need to call the code after the cell has been updated to include the type-ahead field but before the user is actually able to type into it. The best place I found to do this was from an onEditStart event on the property itself. You can add this kind of event by following the steps below.

    1. Login as admin and navigate to TOC > Administration > ItemTypes
    2. Open and lock the Model ItemType
    3. Right-click and view the part_number Property in the Properties tab
    4. Lock this Property in the resulting window
    5. Add a new relationship to a Method in the Events tab
    6. Set the Event to onEditStart
    7. Save, Unlock, and Close the Property

    Now that you have the event attached, we can go over what the method code we want to run will look like. If you throw a debugger into the Method of this Event and try to edit the Part Number from your relationship grid, you'll see that our method code is called before the textbox with the type-ahead is even added to the grid. Because of this, we'll need to run the code that adds our filter inside of a timeout so that it will run after the type-ahead is added to the grid. You can do this with code like below.

    setTimeout(function() {
        var filteredRequest = function() {
            var itemType = this.state.itemType;
            var maxCount = this.state.maxItemsCount;
            var req =
               '<Item type="' + itemType + '" select="keyed_name" maxRecords="' + maxCount + '" action="get">' +
               '<keyed_name condition="like">MP*</keyed_name>' + // Get all Parts with a keyed_name that starts with MP
               '</Item>';
           return ArasModules.soap(req, {async: true});
        };

        // Get the item component
        var itemProp = document.getElementsByTagName("aras-item-property")[0]; // This gets the field that is responsible for populating the type-ahead
        itemProp.request = filteredRequest; // This overwrites the default AML with the request we've specified above
    }, 50); // This calls our function after 50ms

    In the sample above, I've written a new filter to get only the Parts in my system that have a name start starts with MP. Also in this sample, I've set my timeout to 50ms. This small timeout is enough in my local instance, but you may find that you need to increase the timeout in your own system.

    Chris

  • Thanks for the detailed explanation!