This is a migrated thread and some comments may be shown as answers.

Recommended way to disable MarkFirstMatch through JavaScript

1 Answer 93 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 2
Brad asked on 24 Nov 2008, 07:14 PM
Hi,

I would like to get some feedback on the recommended way to disable MarkFirstMatch through Javascript. 

My situation is this:  I have a load-on-demand combo box  MarkFirstMatch = true to allow the users to have autocomplete capability.  However, the combo itself will allow custom text.  We just ran into a situation where the user attempted to enter an item that begins with the same letters as an existing item, but the combo would not allow the text truncation.  For example, the combo has "Principal Software Developer", but the user just wanted to enter "Principal", and the combo box would automatically complete with "Software Developer".   Pressing backspace would delete the "Software Developer" only temporarily, and it would re-appear as you navigated to another control. 

Anyway, I fixed it by adding the following javascript code in the OnKeyPressing event of the combo box:
        function rdlKeyPressing(sender, eventArgs) {  
            if (eventArgs.get_domEvent().keyCode == 8) {  
                sender._markFirstMatch = false//This allows users to enter values not in combo, but shortened versions of existing items.  
            } else {  
                sender._markFirstMatch = true;  
            }  
        }  
 
(Note: In the above code block, "markFirstMatch" begins with underscore)

The above code traps the backspace key, and when pressed, disables the MarkFirstMatch property of the calling combo box.  If the user starts to type anything else, it turns it back on. 

This seems to work fine, but I am a little uneasy relying on an undocumented javascript property.  Is there a better way to do this?

Thanks,

 --Brad

1 Answer, 1 is accepted

Sort by
0
Accepted
Veselin Vasilev
Telerik team
answered on 27 Nov 2008, 08:29 AM
Hello Brad,

You can use the following public methods of the combobox:
  • get_markFirstMatch() - returns true if the MarkFirstMatch property is set to True
  • set_markFirstMatch(true/false) - sets the MarkFirstMatch property
We will add them to the documentation.

Sincerely yours,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
ComboBox
Asked by
Brad
Top achievements
Rank 2
Answers by
Veselin Vasilev
Telerik team
Share this question
or