Explicitly calling the autocomplete function in jquery autocomplete plugin - javascript

I have a text field to which I have a jquery autocomplete event attached. However, due to some reasons, I dont want the search results to appear when the user types, but rather when a button is pressed. I know this sounds lame, but I have my reasons. How do I trigger the autosearch results to appear by calling an explicit function?

Not sure what version of autocomplete you are using. If you use the latest version which is rolled into jQueryUI you can use the search method:
Search :: Signature:
.autocomplete( "search" , [value] )
Triggers a search event, which, when
data is available, then will display
the suggestions; can be used by a
selectbox-like button to open the
suggestions when clicked. If no value
argument is specified, the current
input's value is used. Can be called
with an empty string and minLength: 0
to display all items.

Related

JavaScript in PDF: TextField onAction Listener

How can I achieve an event-call in JavaScript by the PDF when you hit enter on a specific TextField? (alternatively: on every key stroke in that specific TextField)
I've tried
this.getField("field1").addEventListener('input', myMethod);
and
this.getField("field1").events.add(
{
onEveryEvent: function()
{
myMethod();
}
});
but they both do not work.
I found the solution (as described here):
First you have to set a partial name for the field with the PDField.setPartialName(String name)-method, for example myField.setPartialName("myField1");. Then you can access the field via JavaScript in the PDF.
Now use the setAction(..., ...)-method to set your action/event/listener. For example: this.getField("myField1").setAction("Validate", "myMethod()");
Please notice how the second argument is indeed a string and not a method. Also: "Validate" is not just a name and probably only one of many action/event-strings. Unfortunately I do not know what those other strings are. "Validate" is from the docs example and triggers (at least) when
the field loses focus and has changed value in the last focus
you change its value and press enter

jQuery Autocomplete with ajax, can i do a getall?

I have successfully bound my jQuery autocomplete with little trouble. When I type in one or two letters, the ajax query gets me the results and the autocomplete shows the items. I am now wanting to trigger the option to "show all" with a button. I know I can use the code
myInput.autocomplete("search");
to trigger the list when bound to a local datasource. When I try to do it on something bound to an ajax populated source, it doesn't trigger the search with an empty string. I wrote the web api to take an optional query string like below:
public IEnumerable<Account> GetAccounts(string query = "")
Typing in a letter works, remote triggering via a button doesn't for some reason.
Ideas?
Have you checked the minlength option?
It must be zero for empty string. Check the below link for detail.
api.jqueryui.com/autocomplete/#option-minLength

How to force the jQuery .change function to catch user selection from an autocomplete objects

I have the following text field with an auto complete feature:-
Currently I wrote the folliwng to catch what is inside a textbox :-
$("#TextBox").change(function () {
$.getJSON("#Url.Content("~/Switch/LoadRelatedIPs")", { searchterm: $("#TextBox").val(), SearchBy: $("#ChoiceTag").prop("checked") ? $("#ChoiceTag").val() : $("#ChoiceName").val(), },
function (CustomerData) {
The problem I am facing is that the $("#TextBox").val() inside the getJSON , will only catch the value already inside the text box and not what the user select from an auto complete result. For example in the above picture the $("#TextBox").val() will be v10020 instead of the full text which should be v100205 ? can anyone advice how to solve this issue ? and i do not want to use the select inside the autocomplete , since in this way i will have duplicate calls one from the .change and the other from the autocomplete select function ?
The change event fires when the textbox loses focus, which will happen when the user clicks the autocomplete suggestion, which is before the autocomplete javascript fills in the complete value. This is correct behaviour from the change event.
Seems like what you want isn't to execute your code when the Device Resource Tag field changes, but to execute it when a correct (complete) value has been entered. Possible solution: in addition to handling the select event of the autocomplete, when it performs a search, check to see if only one result is returned and it matches what the user has entered, then select that automatically. So in the example above, if the user types out the complete string "V100205", the autocomplete returns one result "V100205". Then you cancel showing the autocomplete and instead execute your code.
It is not clear what code is handling the auto complete functionality. You may need to modify your plugin or script to trigger a change event after setting the new value.
$("#TextBox").val("New Value").trigger("change");
You can also just listen for the various events which fire whenever the text in the input changes:
$('#TextBox').on('input propertychange paste', function() {
});

how to duplicate the value of one form field in another in jquery

I have a form where a user can chose the applications he has access to? and when he the applications he wants access to, he is presented with more options. One of them is notification email address. if the user choses two applications, he gets two notification email address fields to fill. But both of them are stored in the same column in the database.
There are multiple fields like user authorisation level, user branch etc which are uniform accross all applications.
i am trying to replicate the value of one field in the other with jquery. i tried the below which obviously fails. Can anyone suggest how to acheive the replication?
$("#email").val().change(function() {
$("#email1").val($("#email").val());
});
Edit: I have drop down fields as well as text boxes.
.val() returns a string which cannot have a change event. You need to use
$("#email").change(function() {
$("#email1").val($(this).val());
});
You will want to bind the change event using on or live depending on your version of jquery, if you haven't wrapped this piece of code in a ready block.:
$("#email").on("change",function() {
$("#email1").val($(this).val());
});
This fiddle shows setting a <select> tags value using .val() http://jsfiddle.net/8UG9x/
It is an often asked question:
Copy another textbox value in real time Jquery
depending on when you need this action to execute, but if live
$(document).ready(function() {
$('#proname').live('keyup',function() {
var pronameval = $(this).val();
$('#provarname').val(pronameval.replace(/ /g, '-').toLowerCase());
});
});
http://jsfiddle.net/KBanC/
another one, basically same:
JQUERY copy contents of a textbox to a field while typing

Selecting from a drop down ( browser cached drop down ) - which event gets triggered?

Gist
Which event gets triggered when we select from a dropdown which is populated from the cache ( such as usernames and other form values ) in a <input type="text"> .
Detailed
In a form, we can login with multiple username say A,B,ABC . And the browser caches all these values ( w.r.t password remember ). So,if we try to login with A - a drop down pops up giving multiple option say A , ABC -- which event gets triggered once we select any of the options provided.
oninput, onchange, onblur -- none of which seems to get triggered if we select from browser provided drop down.
Help,
Beginner
You can use these events with select.
Cache has nothing to do with the drop down.
What you need is depending on your use.
Generally onchange is used to get the value or call a function when the value changes.
onblur would trigger a function when the drop down losses focus. eg, when you use tab or other methods.
This question is answered here: On input change event?
In modern browsers use the input event. This event will fire when the user is typing into a text field, pasting, undoing, basically anytime the value changed from one value to another.
easily use select event
example:
$('#test').select(function(){ alert('data changed'); });

Categories

Resources