Dave Morse February 2016

angucomplete-alt: getting value of text when it doesn't match

Angucomplete-alt works great for me when trying to force the user into a pre-defined selection among objects.

But if I don't want to force the user to one of those objects, if instead I want the user to be able to enter free text and only have the completions as suggestions, how then do I access the text of the input field?

For example I have a hidden field that marshals the string value of the Angucomplete-alt field for submission to the backend DB. Like this:

<input type="hidden" name="dance[start_type]"
       ng-value="IS_THERE_A_SELECTION ? selectedStartType.originalObject.name : JUST_TELL_ME_THE_STRING_THEY_TYPED"/> 

What expressions should I put for IS_THERE_A_SELECTION and JUST_TELL_ME_THE_STRING_THEY_TYPED?

Answers


Dylan Dechant February 2016

Been banging my head against this one too. Finally just solved it but requires altering some of the angucomplete-alt source. It also uses ng-model for two way data binding.

All you need to do is add

searchStr: '=ngModel',

to the directive's internal scope. Add right after

focusIn:"&"

You now have access to ng-model in in the angucomplete-alt directive.

Post Status

Asked in February 2016
Viewed 2,903 times
Voted 10
Answered 1 times

Search




Leave an answer