andyhill Posted November 2, 2019 Share Posted November 2, 2019 I have a TUnimSelect (Persons) that I want to PreSelect the Focused Item in code before DropDown. My code below makes bold the matching item but the Tumblers do not focus this item with Persons, Persons.JSInterface do begin ItemIndex:= Idx; // This Makes Item Bold but not selected if Idx > -1 then begin // Makes No Difference Text:= SelectedText; Refresh; UniSession.Synchronize; end; JSCall('expand', []); end; Quote Link to comment Share on other sites More sharing options...
Sherzod Posted November 3, 2019 Share Posted November 3, 2019 5 hours ago, andyhill said: I have a TUnimSelect (Persons) that I want to PreSelect the Focused Item in code before DropDown. Hello, Please explain the question once again, providing a complete piece of code or a test case if possible. Quote Link to comment Share on other sites More sharing options...
andyhill Posted November 3, 2019 Author Share Posted November 3, 2019 Persons (TUnimSelect) contains 300 Items, before DropDown we want to seed the selected/focused item using SelectedIdx and SelectedText Persons.ItemIndex:= SelectedIdx; // Does Nothing, Always Positioned at First Item Persons.Text:= SelectedText; // Makes Bold In DropDownTumbler List but not focused Persons.Invalidate; // Does Nothing UniSession.AddJS(MainmForm.Persons.JSName+'.setValue('+Chr(39)+SelectedText+Chr(39)+')'); // Does Nothing Persons.JSInterface.JSCode(#1'.setValue=new "'+SelectedText+'";'); // Errors UniSession.Synchronize; Persons.JSInterface.JSCall('expand', []); // Opens Always Positioned at First Item Quote Link to comment Share on other sites More sharing options...
andyhill Posted November 3, 2019 Author Share Posted November 3, 2019 It appears that TUnimSelect is only half functional ? I want to PreSelect in code the opening focused item on or before Expand. Setting before expand only makes item bold but does not focus it with the DropDown Selection List, it is as if you have hardcoded the ItemIndex to 0 (" ") or -1. // NEVER FIRES s:= 'store.load=function store.load(sender, records, successful, operation, eOpts) '#13#10+ '{ '#13#10+ ' ajaxRequest(MainmForm.window, "_PersonsStoreLoad_", ["Operation="+operation]); '#13#10+ '} '; Persons.ClientEvents.ExtEvents.Add(s); // FIRES (After JSCall('expand', []);) s:= 'expand=function expand(field, eOpts) '#13#10+ '{ '#13#10+ ' ajaxRequest(MainmForm.window, "_PersonsExpanded_", []); '#13#10+ '} '; Persons.ClientEvents.ExtEvents.Add(s); // NEVER FIRES s:= 'beforeshow=function beforeshow(sender, eOpts) '#13#10+ '{ '#13#10+ ' ajaxRequest(MainmForm.window, "_PersonsBeforeShow_", []); '#13#10+ '} '; Persons.ClientEvents.ExtEvents.Add(s); // NEVER FIRES s:= 'show=function show(sender, eOpts) '#13#10+ '{ '#13#10+ ' ajaxRequest(MainmForm.window, "_PersonsShow_", []); '#13#10+ '} '; Persons.ClientEvents.ExtEvents.Add(s); // FIRES (After Close if selection is made) s:= 'change=function change(sender, newValue, oldValue, eOpts) '#13#10+ '{ '#13#10+ ' ajaxRequest(MainmForm.window, "_Persons_", ["val="+newValue]); '#13#10+ '} '; Persons.ClientEvents.ExtEvents.Add(s); Quote Link to comment Share on other sites More sharing options...
andyhill Posted November 4, 2019 Author Share Posted November 4, 2019 Persons (TUnimSelect) After many restless nights and hundreds of tests I have finally come up with a work around as follows using only the events that are fired (remember most Ext Events do not work) and of course pre seeding the SelectedIdx variable before expanding, Note Timing is critical:- ... procedure TMainmForm.PersonsDropDown(Sender: TObject); begin // TUnimSelect is unstable here so we defer our request for 500ms UniSession.AddJS('Ext.defer(function() {ajaxRequest(MainmForm.window, "_PersonsDroppedDown_", []);}, 500)'); end; ... procedure TMainmForm.UnimFormAjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if SameText(EventName, '_PersonsDroppedDown_') then begin if SelectedIdx > -1 then begin with Persons.JSInterface do begin JSCall('getPicker().setValue', [Persons.Items[SelectedIdx]]); end; UniSession.Synchronize(100); end; end; ... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.