last day (14 days later) » 

09:11
0
A: Clear Input Field on Invalid Input Entered in Jquery Autocomplete

masterfanI have tested your code and it works good. The only thing I have changed is $('body').on('focus',".qualification_major_data", function(){ I don't find it useful that you instantiate all array of objects every time you click on the input field. If there's a reason behind it, feel free to leave it...

Thanks, I will keep it in mind for future. (console log). Actually, I am using this auto complete in a different way. User Can Dynamically Add more of this input so I use a class instead of id. I will Explain it to you that This is the Qualification Filed so a user can add more qualification as he wishes so I used a class instead of id for it. Hope You understand.
Feel free to customize it as it fits you the best. It's hard to know only from the code you provided. And yes, console.log is a way to go. You won't be able to inspect the arrays and objects in depth with alert
What's causing your errors (Case1 and Case2)? -- Both the Case. I show the fiddle and it's almost it what I need.
Great, I'm glad if I helped.
This Autocomplete is on the bootstrap model & also in an external Js file. Is it the problem? because it's not working? when I remove that 'focus' code and put the class instead of this.
09:11
You want to use only one class when attaching the autocomplete. $('.form-control').autocomplete({ or $('.qualification_major_data').autocomplete({
where are you stuck now?
1sec i am typing
I have one bootstrap model & in that, I have autocompleted in that. Now User Can Add this Autocomplete dynamically.
Like If user have more qualification to add then he can add more qualifications in that case model has multiple autocomplete.
For Simplification & as per best practices, I have added this scripts to the external js file.
Your Solution is look perfect but did not work in my code.
What exactly is not working now? You can't add class to autocomplete?
If I remove that focus line and add class as you suggested, my autocomplete is not get triggered , it's not working
I have added as you suggested.
var selectedValueID = 0;
$('.qualification_major_data').autocomplete({

lookup: qualifications_major_string,
appendTo: '.qualification_major_div',
minChars: 2,
onSelect: function (suggestion) {

alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
// alert();

var selectedValueID = suggestion.data;

// $('#qualificationForm input[name="qualification_major_id_hidden[]"]').val(selectedValueID);
$(this).closest('.qualification_major_div').find('input[name="qualification_major_id_hidden[]"]').val(selectedValueID);
this is the code.
well, it was just a suggestion. You can stick to the focus line if it works. Just remove alert and add var selectedValueID outside the focus
I have also tried that then the old problem is came back again
the hidden field is not get clear
09:21
did you also remove alert? and put var selectedValueID = 0 outside the focus function
it would be great if you can create JSFiddle so I can test it out
Try Doing this: 1st Enter Wrong Value Which is not in the lookup. We did not get the console at that time.
It's work only when user add correct value first and then if user add wrong value.
I home you are understanding what I am saying.
You should read the documentation for autocomplete
sorry i *hope
onInvalidateSelection: function () {} called when input is altered after selection has been made.
So this is the normal behavior we get
onInvalidateSelection is called only when existing input is changed
ok I get that.
thanks
But Still it is not working in my side.
09:29
what exactly? when you change from div to class?
I will try to make it work with focus
Yes. I get the List it means autocomplete is triggered but when incorrect value i am not going to onInvalidateSelection
Sorry for the bad english
Your Suggested Code is perfect and it's work in jsfiddle.
looks like What i need is the bug in the original codel.
yes, something else is wrong with your code then.
I have to go now, I'll be back later. If I helped you you can accept or vote up my answer
09:46
sure

last day (14 days later) »