Jemt / Fit.UI

Fit.UI is a JavaScript based UI framework built on Object Oriented principles
http://fitui.org
GNU Lesser General Public License v3.0
19 stars 7 forks source link

DropDown: SetInputValue("...") does not work from OnFocus #141

Open FlowIT-JIT opened 2 years ago

FlowIT-JIT commented 2 years ago

The DropDown control does not allow input value to be set from an OnFocus event handler:

dropdown.OnFocus(function(sender)
{
    sender.SetInputValue("Hello world");
});

This is actually by design, but not obvious at all, and could probably be prevented.

Input is cleared on initial focus when in Visual Selection Mode: https://github.com/Jemt/Fit.UI/blob/57490abcd97bdee3d804fa64e41674ce8b2eb7b8/Controls/DropDown/DropDown.js#L1836 So it will sometimes work; the second time control gains focus, or if in Text Selection Mode.

Work around

This is considered a minor bug. There are not many use cases for this type of behaviour, and there are multiple work arounds such as using the OnOpen event instead (although that will not get triggered when using TAB navigation to bring focus to the control), or simply change the input value postponed:

dropdown.OnFocus(function(sender)
{
    setTimeout(function() {
        sender.SetInputValue("Hello world");
    }, 0);
});