Author Topic: How to make drop-down selection disabled on foreign key field?  (Read 958 times)

Offline komgbu

  • Administrator
  • Full Member
  • *****
  • Posts: 16
  • Karma: +1/-0
  • Gender: Male
    • View Profile
Hi!

I need to implement the following functionality:
I have a simple foreign key field on the form (like on picture 1). I have a custom implementation of on-click event for the spyglass button.
Now I want to hide the arrow, because I won't allow users to select something manually.
I spent a half of day to make this code...

onFormCreated: function () {
        this.callParent(arguments);
        //custom spyglass processing
        this.formView.controlListen("Project_Manager_Id", Uxc.lib.types.ControlEvents.SpyglassIconClick, this.onProjectManagerSpyglassIconClick, this);
        //hide arrow
        var pmControl = this.formControl.getControlByDataName("Project_Manager_Id");
        pmControl.widget.el.dom.childNodes['1'].childNodes['0'].childNodes['1'].style.visibility = "hidden";
        pmControl.widget.el.dom.childNodes['1'].childNodes['0'].childNodes['1'].style.width = "0";
    },

    onProjectManagerSpyglassIconClick: function (control, tableName, options) {
        Uxc.lib.Dialog.showQuestion("Select from TOP managers?", Ext.MessageBox.YESNOCANCEL, this.onProjectManagerTypeSelected, this);
        return false;
    },

Now my control looks like on picture 2.
One issue which I still need to fix: If user will focus on the field and press down button on keyboard, the drop-down list will be displayed and user will be able to select any values from it.  >:(

Anybody know the simler way to make this?...
I've read about the ability to make the field read-only in the Toolkit, which should make the spyglass still available... but it doesn't work for me...  :(


I've used the following example from Aptean KB as prototype:

In order to hide the down arrow button in a foreign key field in an Active Form, add the following code in “OnFormLoaded” function of the form:

---------------------------------------------------------------------------------------
Dim objHTMLDoc, objTDElements, objTDElements
Set objHTMLDoc = UIMaster.RUICenter.GetForeignFieldEx("", "Set objTDElements = objHTMLDoc.GetElementsByTagName("TD")
For Each objTDElement In objTDElements
If objTDElement.className = "ForeignFieldBtn" Then
objTDElement.Style.visibility = "hidden"
objTDElement.Style.Width = 0
End If
Next ' objTDElement
---------------------------------------------------------------------------

is the name of the tab in which the field exists.
is the name of the segment in which the field exists.
is the name of the foreign key field to be modified.

Thanks in advance for your help!
http://www.bfs-corp.com/

26 Bloomsbury Street, London WC1B 3QJ
Switchboard & Fax +44 (0) 845 057 4148

Offline Ashish Iddya

  • Jr. Member
  • **
  • Posts: 8
  • Karma: +1/-0
    • View Profile
Re: How to make drop-down selection disabled on foreign key field?
« Reply #1 on: August 03, 2017, 10:02:21 AM »
Hi,
You can also set the control to read-only in the script.
var foreignKey = this.formControl.getControlByName("Project_Manager_Id");
if(foreignKey)
{
      foreignKey.readOnly = true;
}

Maybe this would solve the issue?