Get value from autocomplete text field in ApEx - oracle

I want to create a dynamic action, that will set a value to an item on the page, when the value of another item (autocomplete text field) is set.
So the proccess goes like this:
Click on the autocomplete field
type some letters
choose one of the suggested values
I cannot find an event that will be executed when the selection of one of the suggested values happens. This way, I cannot see how I can read the value of the autocomplete field, once a suggested value is selected.
The change event doesn't fit my needs, it doesn't execute when one suggested value is selected.

I had the same problem, found this link: https://community.oracle.com/thread/2130716?tstart=0 and modified my dynamic action as follows to get the desired behaviour:
Event = Custom
Custom Event = result
From the link:
the problem seems to be the default behavior of the browser. When you
enter some text into the autocomplete and the list is displayed, the
focus is still in the text field. Also if you use the keyboard cursors
to pick an entry the focus will still be in the textfield. That's why
the change event of the textfield doesn't fire. It only fires if you
leave the field.
On the other side if you pick an entry with the mouse, the browser
will remove the focus from the text field for a moment (before the
JavaScript code puts the focus back), because you clicked outside of
the field. But that's enough so that the browser fires the change
event.
I had a look into documentation of the underlaying jQuery Autocomplete
widget
(http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/) and
there is actually an event called "result" which can be captures if an
entry is selected from the drop down list.

Try "Lose Focus" as event. It will trigger your dynamic action when you leave the autocomplete field, i.e. your curosr is moved to another field.

This probably depends on the APEX version you are using.
In case of 18.2, because the underlying component is based on Oracle JET's "inputSearch" component, you need to use following configure to capture the select change event for text with autocomplete:
event: Custom
custom event: ojupdate
Reference:
https://docs.oracle.com/cd/E87657_01/jet/reference-jet/oj.ojInputSearch.html#event:optionChange

I turned on the browser console, then turned ApEx Developer toolbar debug, and found that, on the contrary, the "Change" event does fire upon user clicking with the mouse on one of the selections. However if the user uses keyboard (type a few letters to narrow the list down, then use down arrow key to arrive at desired value, then press enter) then the Change event does not fire, just as you say.
Moreover: even when you do get the value sent back via mouse-click initiated Change event, the value isn't the autocomplete's complete and valid value, but instead the possibly partial and wrong-case value just as typed by the user. I.e., the the change event's submission of the value precedes the autocomplete's substitution.
The answer that #VincentDeelen gave is the best alternative that I can see, although it doesn't quite give that "instantantenous synchronicity" feel. You could maybe use the "Key Down" event, but be careful with that. You could get a really excessive amount of web and db traffic as each and every keystroke (including corrections) results in another firing of the dynamic action.
Testing environment: ApEx 4.2.3 with Chrome 33 as well as IE 9.
p.s. This might be worth a mention to the ApEx development team as well.

It's not really ideal, but you could use onfocus(). I'm looking for the same thing you are, I think, a custom event that fires when the selection of a suggested value happens. I haven't found it yet though and that is my work-around for now. It will run whatever function you've created for this initially with no value, but once the selection is made it will return focus and run the function again with the right value. Like I said, not ideal but it works.

Jeffrey Kemp is right. You can set it up through a dynamic action using the custom event, result. You can also register it on page load using document.getElementById("{id}").addEventListener("result", {function}); or $("#{id}").result( function( event, data, formatted ) { //something here });.

Oracle apex 19 now added a "component event" when you create a dynamic action called "Update [Text Field with autocomplete]" - this action is fired when you select a value from the list, but not when you leave the field (similar to adding the custom event "ojupdate").

Related

Field must be entered not shown

I have a required field. It has two triggers:
key next item
when validate item
The built-in message FRM-40202 - field must be entered is not shown in status bar, but when I delete key next item trigger it is shown .
Please, explain to me why this happened and how can I solve this or - at least - how to show the built in message .
thanks
Check form's Property Palette, its "Validation Unit" property. What is it set to? Should be "Item" if you want that validation fires when you leave that required item.
Apart from that, KEY-NEXT-ITEM trigger is here for backward compatibility to Forms 3.0 which was the last version that used character mode, where there was no mouse involved (i.e. navigation was only through keyboard actions).
Nowadays, people use mouse and click here and click there to move through the form, so there's no guarantee that KEY-NEXT-ITEM will ever fire. Its code should be moved to WHEN-VALIDATE-ITEM which you already have. So, if both of them contain same code, and if you (as you said) deleted the KEY-NEXT-ITEM trigger, so be it. It is useless anyway.

Angular Material md-select load options in async way

I need to load select's options asynchronously (
through a service), using the Angular Material md-select component.
Actually, I use a click event to load data. It works but I need to click the select twice to show the options. That it's a problem.
The expected behavior is shown at this link (AngularJs Material)
The actual behavior is shown at this link.
Is Async options' loading supported by md-select?
The reason you need to click twice is because when you first click, there are no options in the select control and so it doesn't try and open the panel. Then your async method loads the options into the DOM and on the next click it will open.
In order to deal with this, you must always include at least one <mat-option> in your <mat-select>. You can add a disabled <mat-option> with a <mat-spinner> showing that the data is loading for example.
Here the most simple example of that. This is not the best approach... see below.
However, this still uses the click event which isn't the best approach. If you put the click event on the <mat-select> there are spots where you can click on the control but your click event wont trigger even though the dropdown panel still opens (places like the floating label area). You could put the click event on the <mat-form-field> but then there will be places where you can click and trigger the click event but the dropdown panel wont open (places like the hint/error text area). In both cases you lose keyboard support.
I would suggest using the <mat-select> openChanged event instead of a click event. This has its own quirks too but they are manageable.
Here is an example using the openChanged event. I also made the component more robust overall.
I also made a version that uses the placeholder element to show the spinner instead of using a disabled mat-option. This required View Encapsulation to be turned off.
Note: In my example, the service can return different data depending on the circumstances. To simulate this my fake service keeps track of how many requests you send it and changes the options returned accordingly. So I have to set the option list back to empty and clear the formControl's value every time the list is opened. I save the selected value before clearing the formControl so that if the service returns a list with the same item I can automatically reselect the value. If you only need to load the options once, then you would want to modify the code a bit to only load the options the first time the user opens the select.

How to Asynchronously Show a Create New Button On a CRM Sub Grid?

I need to hide the "Add New" button on a sub grid until certain criteria are met. Calling Xrm.Page.ui.refreshRibbon will trigger my JS function defined in my Enable Rule, but I can't get the + button to show up.
Is this unsupported, or is there some methodology to get this to work?
Seems like you have to do few extra trick.
Refreshing the subgrid command bar
You will find that when the form is loaded, if there is a value in the attribute you have referenced in your enable rule, the Add New button will be visible. If however the value changes, the sub-grid command bar will not automatically refresh to reflect the new state. Upon adding or deleting rows in the sub-grid the command bar is refresh – but this isn’t much use in this case.
The main form command bar can be refreshed using Xrm.Page.ui.refreshRibbon() however this will not refresh sub-grid command bars. Instead, we can add an onchange event to the fields that are used in our VaueRule and call:
Xrm.Page.data.save();
This will refresh the sub-grids and re-evaluate any of the EnableRules however it will also save any other dirty attributes and so should be used with caution if you do not have auto-save enabled.
Ref: https://ribbonworkbench.uservoice.com/knowledgebase/articles/489288-show-or-hide-the-add-new-button-on-form-sub-grid
Arun Vinoth did find a great article to describe the issue, but actually I've found that just calling refresh on the grid itself was all that was actually required.
It's important to note, that this does not re-run the enable rules, just shows the button if the state has changed.

Filter every character in Kendo Grid

How do you force a Kendo grid to filter data after every character is typed, as in after every letter, not just when I press enter button?
I noticed that Kendo sends requests after every character typed, but without page size, and this request is used for autocomplete. I want to change that to bind this data not to autocomplete, but to the main grid instead.
I am using built in filters, one for each column.
Sorry for later response, I didn't have much time. Anyway as I mentioned in comment, this functionallity is not supported by Telerik. So you have to create everything by yourself.
In following example I have used filterMenuInit event which is fired after you click on filter icon (and only once!). In that event I have modified filter elements to add custom classes and ids. Then in jQuery I am catching keyUp events and adding items into filter.
Here is small example. I have implemented only equals filter, so you will have to do some modifications. But I hope it can help you in next work.

In FoxPro, why is selected table changing within form if form called from a button in a grid?

I have a master form that calls a form called freight.
This freight form has all properties set to default except Caption, Name and window type which is 1-Modal.
The only method with code is the init which has:
select FRT1
The only object on the form is a command button with this in the click method:
messagebox(alias())
thisform.release()
So I would expect when I press the command button, the messagebox would say [FRT1] but instead it gives another alias from the master form.
Before the form is called from the master form, the alias is also explicitly set to FRT1
select FRT1
do form freight
Because the Freight form is modal, I would expect nothing in the master form to affect the data areas while the Freight form is running.
Since there is practically nothing in the Freight form, the problem would seem to be in the master form.
This errant behavior seems to only occur if the freight form is called from a button within a grid. Any ideas on what is happening or how to prevent it?
Aren't there any controls on the called form (typically a grid) that gets the focus and hence implicitly cause a change to current workarea?
BTW, I suggest using private data session and keeping each session separate.
Just a few thoughts.
I would open your debugger and put a
SET STEP ON
immediately before doing the
SELECT FRT1
DO FORM FREIGHT
Then, in the debugger, go to the "Watch" window and enter the value
ALIAS()
as the value to watch and to a click in the left-bar to show the red dot to STOP when it changes.
Just a thought of expectation. Your "Freight" form has its "DataSession" property to "1-Default data session", and if so, it is looking at whatever alias is in the DEFAULT session and not a PRIVATE data session that your master form may have...
I have seen this only EXTREMELY RARE cases ( 2 times ever in the 25+ yrs of working with FoxBase, FoxPro, VFP). In these cases, I had to EXPLICITLY do a select of the table TWICE in a row.
SELECT FRT1
SELECT FRT1
or even putting a bogus statement in between such as
SELECT FRT1
tmpXXXXXX = alias()
SELECT FRT1
Check with breakpoint and see if that works.
Only one other breakpoint I would TRY to do... put "PROGRAM()" in the watch window. Is it possibly calling some other derived class script you did not know about... or in the "DataEnvironment" of the form running code such as in the "BeforeOpenTables" event? Better to KNOW where its doing things than bypass

Resources