0

What I am trying to do: A custom filterable dropdown menu. The list item gets dropdown on-focus on input element . The options are selectable and it's text should appear in input field when clicked. The list view should go away when input not focused.

Problem: The list item click event couldn't be triggered as list view gets removed on blur( on-blur="bool=hide").

Demo:http://jsfiddle.net/Dreamerpro/3s5c62Lx/2/

PS: I can solve using jquery but since I am learning Angular so I want to do it in angular way and sorry for my English :P

3 Answers 3

1

You can try this.

instead of assigning bool = false on blur. you can do this inside setModel() function.

see http://jsfiddle.net/rzs9osob/

EDIT: Replaced ng-click with ng-mousedown and retained ng-blur handler. Updated fiddle: http://jsfiddle.net/g9p4dpdd/

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks :D. That was too easy.
Can you please provide solution for what @Will has said.
You can try ng-mousedown and retain ng-blur handler. see updated fiddle. jsfiddle.net/g9p4dpdd @Will, nice catch. I didn't see that.
0

@Prince, I can't leave a comment in your answer, but your jsfiddle works except I would still leave the ng-blur="bool = false" in so the drop down goes away when the user clicks somewhere else.

1 Comment

yeah. I actualy forgot to say that
0

Slight modification to the code will get you your result.

Working Fiddle

Explanation: You are using bool = false in your onblur attribute. Instead use that in your method which is used to set the value. This way, the list will be available even after loosing focus from the input field.

Hope this helps

1 Comment

Yes, thanks for reply, but I need to hide the list-item on blur and if clicked then set the input value to the clicked item text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.