I'm building an autocomplete component which is loaded dynamically from the parent using
<div>
<input type="text"
:placeholder="myResources.Placeholder" #input="onChange" #keyup.down="onArrowDown" #keyup.up="onArrowUp" #keyup.enter.prevent="onEnter($event)" #blur="onBlur"v-model="search" />
<ul id="autocomplete-results" v-show="isOpen" class="autocomplete-results">
<li class="loading" v-if="isLoading">
Loading results...
</li>
<li v-else v-for="(result, i) in results" :key="i"
#click="setResult(result)" #mouseover="onMouseOver(i)"
class="autocomplete-result" :class="{ 'is-active': i === arrowCounter }">
{{ result }}
</li>
</ul>
</div>
Basically when the user starts typing a list of search results shows up, and they can select between the results using the up and down arrow keys, and then confirm their choice by pressing enter (or they can use the mouse).
Problem is, the component is placed inside a tag in the parent. And pressing Enter submits the form. I have tried catching the event, using
#keyup.enter.prevent="onEnter($event)"
or calling event.preventDefault() in the event handler. None of this works. Breaking inside the event handler, I found out that the submit on the form happens before the handler is triggered. I thought maybe the event originates on the or elements, but when I stick event handlers on them, they don't get called.
How do I tell the parent "don't submit" and actually have it listen?
As I mentioned, the component is rendered dynamically inside a parent. The problem
In your onArrowUp and onArrowDown functions, you should focus() the child component. That way, the Enter key is definitely called on the child item.
From there, change your #keyup.enter.prevent to #keyup.enter.stop to stop event propagation back up to the parent.
Related
My element looks like this:
<div id="searchBarFilters">
<div class="filterBox">
<div class="col-xs-12">
<h3>Adjust Filters<span ng-click="closeGlobalFilters()" class="icon-close"></h3>
<hr/>
When the user clicks on this close icon, the particular div panel visibility is hidden. I am checking this functionality using protractor as below:
browser.driver.findElement(by.css('span[ng-click*="closeGlobalFilters()"][class="icon-close"]')).click();
I had to use both the attributes of span tag because there are 2 other elements with the same className.
The above code is not showing any error but I do not see the click action eing executed in action.
What am I missing here? Thanks in advance for your help.
I'm trying to use popover for certain parts of paragraphs that I'm fetching from my DB and using ng-repeat I load to my html and serve to the front-end.
The relevant part of my DOM, looks like this
<div ng-repeat="i in comments" class="ng-scope">
<div popover="test2" class="task ng-binding"> text1
<span popover="test" class="highlight-a">text2</span>
</div>
</div>
the ... is injected into the DOM from after some process in the back-end, so the basically the DOM is modified after it loads and renders.
At this point, clicking on the won't trigger any popovers.
I'm wondering if there's a work-around for re-initiating the popovers or anything like that. Even when I call on to load the popover in the end of the process it doesn't work.
Hi I have a following html markup
<h2>First Name Last Name</h2>
<form>
<div>
<input name="fname">
<input name="lname">
</div>
</form>
You click on a header to show the form fields and to edit them (blur hides the fields and shows the header again).
I have a problem because the first and last name are in the same header, so you click on one item to edit two fields.
I am submitting the form on a blur event for the input fields but when I click the last name, because blur is being called in the first name, I cannot edit the second field.
I am using AngularJS which is also presenting a problem because I cannot figure out which element is focused because document.activeElement returns the entire body.
Any help is much appreciated!
Assuming you're using ngBlur directive on the input element, you can mix it with ngFocus to keep elements visible as wanted: <input name="fname" ng-focus="showFields=true;" ng-blur="blurField($event);" >
Using a function for ngBlur, you will have access to the $event object which in turn will expose the elements you need (like target or related). Afterwards, you can trigger form submit depending on your needs.
A demo plunker is HERE.
I cannot get a form to submit additional fields that have been cloned. When a form like the one below is submitted, it does not include the cloned form elements. Does anybody know why and how I can alleviate this issue.
<form>
<table>
<tr><td><input type="text" value="50" name="myvar[]" /></td></tr>
<!-- This button will clone the previous set of form elements -->
<tr><input type="button" value="Add New Line" onclick="this.getParent('tr').getPrevious('tr').clone().inject(this.getParent('tr'), 'before')" /></tr>
</table>
</form>
Your HTML isn't well formed, so this.getParent('tr') is returning null at least for me in Firefox. Put the button inside a td that is inside the tr and it works.
JSFiddle: http://jsfiddle.net/delvarworld/r99fN/ clicking the button throws an error
Thanks for the comment but the form was meant to be an example not actually what I had. I looked back at the form and the top form element was inside the table and the bottom form element was outside of the table. I moved the top form element outside of the table and everything works perfectly.
thanks,
I have a piece of code like this.
<form method="get" action="{$self}" name="addcommentform">
<textarea title="{$enterComment}" name="comment" class="commentarea" </textarea>
<input class="Button" type="submit" value="{$postComment}" />
</form>
How do I keep track of when what is the text entered in the form's textarea when the user navigates away from the page? I want to prompt the user with a warning message so he/she doesn't lose the text.
Thanks.
You could use the javascript/jquery blur event, and if the user hasn't clicked the desired button have it display the form values. This might help JQuery Blur Validation Problem
Stu
Take a look at this Javascript code snippet:
http://www.boutell.com/newfaq/creating/disableclose.html
This takes advantage of the window's onbeforeunload event which fires when the user is about to leave the page.