Is it possible to prevent keyboard entry in the SimpleCombo? I looked for a property but I did not see one.
I have a list of items that are displayed in a SimpleCombo, and I don't want the user to free-style an entry in the text area.
I want something that resembles the UltraWinCombo DropDowStyle = DropDownList, where a keyboard entry will select the nearest entry in the list, but won't allow values in the Combo that are not predefined in the list.
Hello,
Thank you for reaching out with your request to prevent free-text entry in the igx-simple-combo component while allowing only predefined list selections. Ignite UI Angular’s igx-simple-combo does support configurations to meet this requirement. Below is the recommended approach to ensure users can select only from the provided list without entering custom values.
Solution Overview
To achieve the desired behavior, we’ll leverage two main techniques:
This approach will ensure the combo acts similarly to the UltraWinCombo’s DropDownStyle = DropDownList mode, allowing users to select the nearest entry in the list without allowing free text entries.
Code Implementation
Below is the detailed code implementation using these techniques:
HTML Template
<igx-simple-combo [data]="items" [(ngModel)]="selectedItem" [allowCustomValues]="false" (keydown)="preventInput($event)"> </igx-simple-combo>
Component TypeScript
In the TypeScript file, add a method to handle the keydown event, which will prevent any keyboard entry:
export class YourComponent { items = ["Item1", "Item2", "Item3"]; // Replace with actual data source selectedItem: string; preventInput(event: KeyboardEvent) { event.preventDefault(); // Blocks all keyboard input } }
Explanation of Code
With this configuration, users will only be able to navigate and select values using the combo’s dropdown menu. Typing will automatically search for and select the closest matching entry.
Please feel free to reach out if you have any questions or would like further adjustments to this solution.
Regards,
Georgi Anastasov
Entry Level Software Developer
Infragistics