ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Call a method on selecting a field using autocomplete
Title:
B
I
{code}
?
Hi I am using the autocomplete control of awesome. I am able to implement it successfully , but I also want to call a method after selecting the value from autocomplete dropdown. How to achieve that. Regards Tanuj
Save Changes
Cancel
Tanuj Shrivastava
asked at 22 Sep 2016
you can try and bind to the change event
at 22 Sep 2016
Omu
yes but change event will work for methods of view controls like dropdowns, grids , etc. and changes will reflect on that control. I want to call a method which will work internally
at 23 Sep 2016
Tanuj Shrivastava
you bind to the change event of the autocomplete ( using it's id), not the change event of the whole document
at 23 Sep 2016
Omu
can you provide me an example for the same , I am not getting it ? like using jquery
at 23 Sep 2016
Tanuj Shrivastava
$('#autocompleteId').on('change', function(){ alert('hi'); });
at 23 Sep 2016
Omu
my validation is not working in case of autocompletefor , earlier I was using editorfor and it was working fine
at 26 Sep 2016
Tanuj Shrivastava
the EditorFor helper uses partial views from Shared/EditorTemplates, in our demos all these views have a layout _FieldLayout.cshtml that has the Html.ValidationFor helper and the label, so now since you're not using Editor for you need to add the label and the ValidationFor helper yourself
at 26 Sep 2016
Omu
thanks , its working fine now, I am able to call a method on change event as well as validation working fine, but I am not getting the id of selected item when calling the method using jquery
at 26 Sep 2016
Tanuj Shrivastava
http://demo.aspnetawesome.com/AutocompleteDemo#Storing-selected-value-key-in-a-separate-field-using-PropId
at 26 Sep 2016
Omu
I am not able to get the value of hidden field, I have changed the ID of hidden field :- @Html.Awe().AutocompleteFor(o => o.CompanyName).PropId(m=>m.ContactID) @Html.ValidationMessageFor(o=>o.CompanyName) @Html.HiddenFor(m=>m.ContactID, new { id = "ContactIDforCompany" })
at 27 Sep 2016
Tanuj Shrivastava
PropId("theactualid") why are you setting new { id = "ContactIDforCompany" } ? .PropId(m=>m.ContactID) will look for "ContactID"
at 27 Sep 2016
Omu
actually I am already having a hidden field for ContactID on my view page, due to which I am facing problem during post method. For now I have created separate property for this , but still I want to ask that if this is possible, to read value from hidden field with different ID
at 28 Sep 2016
Tanuj Shrivastava
there is, I just showed you PropId("theactualid")
at 28 Sep 2016
Omu
Answers
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK