Vue 2.0 multiple keyup on button - methods

I have a problem with Vue, I have a code that run good #click, but I want to add keyboard handlers also. This is the code :
<section v-else class="row controls">
<div class="small-12 columns">
<button #click="playerAttack" #keyup.a="playerAttack" id="attack">
ATTACK
</button>
<button #click="specialAttack" #keyup.s="specialAttack" id="special-attack">
SPECIAL ATTACK <br />
<span>Cooldown : {{ this.specialCooldown }}</span>
</button>
<button #click="playerHealing" #keyup.h="playerHealing" id="heal">
HEAL <br />
<span>Cooldown : {{ this.healingCooldown }}</span>
</button>
<button id="give-up">GIVE UP</button>
</div>
The point is, on first button, 'Attack' in this case the keyup event works fine from start. Unfortunately the 'Special Attack' and 'Heal' doesn't, but... When I clicked on any of these two keyup event seems to change, and now 'Attack' is not working with the non clicked button 'Heal' f.e. but 'Special Attack' works fine, until I clicked on 'Attack' or 'Heal'. The keyup event are changing to fire last clicked button, and keyup is recognized correctly.
I don't think this is methods problem cause everything works fine #click and also #keyup when last-clicked button keyup event is invoked. Is it problem with code or I am not knowing some Vue specifics?

In JavaScript Events always origin from an element and bubble upwards through their parent elements. Keyup Events origin from the currently focused element.
Your event listeners only catch the keyup event if the button on which the listener is defined is focused.
To solve the problem you can try listening to keyup events on an element that encloses the buttons, e.g. the section element.
<section v-else class="row controls"
#keyup.a="playerAttack"
#keyup.s="specialAttack"
#keyup.h="playerHealing">

Related

Cypress Tool -- how to do click action on Show and Hide button, unable to do action on this button

i have a scenario like below with hide and show button
when i fill some data in input box action witll show me button else button is in hide mode
the below is the code , please suggest me solution how to run my automation code after entering code in input box
when button enabled mode -- with out text entering in input box
<button data-v-320fbb42= type="button" disabled="disabled" class="btn z-btn mr-1 btn-primary rounded-0 disabled" style="position: relative;"><div data-v-320fbb42= class="d-flex flex-row justify-content-center align-items-center">Save </div></button>
else
when button disabled mode -- after entering proper text in input box
<button data-v-d0c5d35c= type="button" class="btn z-btn mr-1 btn-primary rounded-0" style="position: relative;"><div data-v-d0c5d3c= class=d-flex flex-row justify-content-center align-items-center>
Save </div></button>
so i tried all the scenarios like below , but noting is working ,
cy.get('button').should('be.disabled').invoke('show').should('be.enabled').contains('Save').click()
cy.contains('Save').click({force: true})
cy.get('button', 'Save').should('be.disabled');
cy.contains('button', 'Save').click();
Thanks for your suggestion or help
Since your disable status is based on a class - I have found the next solution for validation in https://docs.cypress.io/api/commands/should.html#Value
cy.get('button', 'Save').should('have.class', 'disabled')
cy.input(inputSelector).type(text)
cy.get('button', 'Save').should('not.have.class', 'disabled')
And a solution for forcibly enabling it
$(selector).removeClass('disabled')
cy.get('button', 'Save').should('not.have.class', 'disabled')

#keyup.enter is not working with <cleave> [duplicate]

I have a Vue component with
an <input> element that binds the v-on:keyup.enter key to doFilter()
a <button> that binds the v-on:click event to doFilter()
<input type="text" v-model="myVar" #keyup.enter="doFilter" />
<button #click="doFilter">Filter</button>
The button event will fire doFilter(), but the key up event will not fire, unless I add the .native modifier.
<input type="text" v-model="myVar" #keyup.native.enter="doFilter" />
The Vue.js documentation says this about .native:
listen for a native event on the root element of component.
When do I need to use .native and why does the keyup event not trigger without it?
Update 1: Add codepen and code
Runnable demo at https://codepen.io/hanxue/pen/Zapmra
<div id="app">
<md-toolbar>
<h1 class="md-title" style="flex: 1">#keyup.native event</h1>
<md-button class="md-icon-button">
<md-icon>more_vert</md-icon>
</md-button>
</md-toolbar>
<md-input-container>
<label>#keyup.enter</label>
<md-input type="text" #keyup.enter="doFilter" placeholder="#keyup.filter">
</md-input>
</md-input-container>
<md-input-container>
<label>#keyup.native.enter</label>
<md-input type="text" #keyup.native.enter="doFilter" placeholder="#keyup.native.filter">
</md-input>
</md-input-container>
<md-input-container>
<button #click="doFilter" placeholder="#keyup.filter">
#click </button>
</md-input-container>
</div>
<script>
Vue.use(VueMaterial)
var App = new Vue({
el: '#app',
methods: {
doFilter: function() {
alert('doFilter!')
}
},
})
</script>
Based on your comments, I'm assuming that you're using the Vue Material libary and the <md-input> component instead of an <input> element.
If you listen to the keyup event without using the .native modifier (via <md-input #keyup.enter="doFilter">), then your component is waiting for the <md-input> component to emit a custom keyup event.
But, that component does not emit a keyup event, so the doFilter method will never be called.
As the documentation states, adding the .native modifier will make the component listen for a "native event on the root element" of the <md-input> component.
So, <md-input #keyup.native.enter="doFilter"> will listen to the native keyup DOM event of the root element of the <md-input> component and call the doFilter method when that is triggered from the Enter key.
I had the same problem on a custom vue component on which I was listening to both #select and #keyup.native.enter and I was receiving the Enter key twice because I didn't pay attention: onSelect emits an onKeyDown for Enterand onkeyUp flared secondly.
My solution was to listen to #keydown.native.enter so that the #select cycle of keys was unbothered (which is keydown -> keypresssed -> keyup).

Invisible Recaptcha Badge Positioning Issue

I recently started using Google's new method of Recaptcha - their new Invisible Recaptcha. I realized that the implementation of this version was a little different, as you attach the recaptcha attributes directly to your submit button which then calls google's recaptcha api and begins the verification process. I have all of that working fine, but the one major issue that I am having is with the "Protected by recaptcha" badge positioning.
Upon adding the recaptcha configuration to my submit button, I start seeing the badge on the right of my screen. According to other sites, this badge is supposed to just be a square recaptcha logo until it is hovered and then it is supposed to slide out to be the large rectangle that I am seeing initially on my site.
Here is an image of what I am seeing on my site after implementing the invisible recaptcha.
Here is the submit button code containing the recaptcha attributes:
<button class="btn btn-primary btn-block g-recaptcha" data-sitekey="key"
data-callback="submitsecure" data-badge="bottomright" type="submit">Get Started</button>
Note: The other data-badge options such as inline and bottomleft cause the same positioning issues.
The code of of the form containing the button:
<form action="processjoin.php" method="post" id="signupform" style="padding-top:10px;padding-bottom:10px;max-width:50%;">
<h2 class="sr-only">Login Form</h2>
<div></div>
<div class="illustration"><i class="icon ion-ios-pulse-strong"></i>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" name="name" placeholder="Your Name" class="form-control" id="name" />
</div>
<div class="form-group">
<input type="text" name="username" placeholder="Username" class="form-control" id="username" />
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input type="email" name="email" placeholder="Email" class="form-control" id="email" />
</div>
<div class="form-group">
<input type="password" name="password" placeholder="Password" class="form-control" id="password" />
</div>
</div>
</div>
<div class="form-group">
<button class="btn btn-primary btn-block g-recaptcha" data-sitekey="6LfdMhkUAAAAAHl-LXZm_gPP1g-UX0aWt8sMR4uW" data-callback="submitsecure" data-badge="bottomright" type="submit">Get Started</button>
</div>
<a href="#" class="forgot">
<div></div>Already have an account? Sign in.</a>
</div>
</form>
I am experiencing two issues with this recaptcha badge:
The badge is glitched outside of its bounding box/border type thing
It also isn't positioned partially off-screen until hovered, like it is supposed to be. I am seeing the full rectangle before I interact with it in any way with my mouse. I should be seeing the square logo until I hover over it, and it slides out to be the full rectangle.
Basically, I need to figure out how to position this properly so that it slides in from off-screen like it is supposed to, and is contained properly inside of its border.
Google Chrome Developer tools tell me that these are the current attributes of the badge div, generated when the window is loaded:
I really appreciate any help that you can provide! If I'm incorrect in thinking that the badge is required, please correct me and I'll force its removal with CSS, however, I'm afraid that this may mess up the captcha verification process and violate Google's policy.
This might help: https://developers.google.com/recaptcha/docs/invisible#config
You can set data-badge="inline" to allow you to control the CSS.
After lots of trial and error, I figured out that the recaptcha badge was positioning to its containing element rather than to the body, and it was also inheriting its line-height from its containing element.
Since I was not directly able to remove the badge from its containing element and move it to the body, I solved the issue with JQuery and a slight CSS change.
JQuery: Appened the badge to the body rather than its containing element (the form)
In order to do this, I had to ensure that the badge had already been fully loaded into the site. Google makes this difficult, but I was able to do it by using jQuery.initialize by timpler.
Once I had the initialize.min.js running on my page, I simply used this code:
jQuery(document).ready(function() {
$('.grecaptcha-badge').appendTo("body"); //fix recaptcha positioning to body
});
$.initialize(".grecaptcha-badge", function() {
$(this).appendTo("body"); //fix recaptcha positioning to body, even if it loads after the page
});
CSS: Added a change to the line-height to position the badge properly with its container
.grecaptcha-badge {
line-height:50px !important;
}
This was a tough one to figure out, but in the end it simply came down to the badge inheriting a few too many attributes from its parent. I hope this helps someone in the future!
You can add captcha in a div element at any place on the page
<div class="g-recaptcha"
data-sitekey="your_site_key"
data-callback="onSubmit"
data-size="invisible">
</div>
When you submit the form the following javascript should be called to start captcha validation
grecaptcha.execute();
The onSubmit function (specified in data-callback tag attribute) will be called on successful captcha validation. There you get the recaptcha token that can be injected as hidden field to your form for backend validation.
function onSubmit(recaptchaToken) {
// inject token as hidden form field and submit form
}

how to handle multiple submit buttons in spring mvc in java. One Submit buttons is for Server side and another is only for Client Side

I am trying to handle multiple submit buttons in spring mvc in java. 1st Submit buttons is for Server side call and 2nd Submit button is only for Client Side call.
But here the problem here I am facing is, for both submit button, control is going to Server side . I am Using plane jsp with spring tag. Here my requirement is one submit button should work for server side & another submit button only works for client side.
CODE Snippet:
<body>
<div>
<form:form commandName="route" method="post" action="routeSave" id="route">
<div class="center">
Start:<form:input path="start" id="start" maxlength="50"/>
End:<form:input path="end" id="end" maxlength="50"/>
City:<form:input path="city" id="city" maxlength="50" onchange="mapcenter()"/>
RouteName:<form:input path="routeName" id="routeName" maxlength="50"/>
StartTime:<form:input path="startTime" id="startTime" maxlength="50"/>
<form:button value="SaveMap">Save Button</form:button>
<form:button value="SaveMap" onclick="save_map()">Save Map</form:button>
A button of type="button" will not submit a form to a URL. A button of type="submit" (the default) will. So use a type="button" button for the client side action.
<form:form>
<button type="button" name="btn1">no submit</button>
<button type="submit" name="btn2">submit</button>
</form:form>
You can try it with for Example jQuery:
$( "#route" ).submit(function( event ) {
event.preventDefault();
});
The event Element has additional Information to handle it in handler-Method. See jQuery Docs.

Closing a dialog mvc3

I have en dialog box where there is an CKEditor inside. But i can't get it to fire the HTTPPost on the partialView.
<form method="post" action="#Url.Action("Description")">
#Html.CKEditor("text", (string)ViewBag.BodyText, "toolbar:'Full'", new { cols = 2000, rows = 5000 })
<p>
<input type="submit" value="#Resources.Resources.ProjectCreateDescriptionSave" onclick="#Html.CKEditorSubmitButtonUpdateFunction();" class="close"/>
</p>
</form>
It requires the class="close" but if it's in the input it closes but dosen't fire the httppost. But if i remove the class="close" it works prefect. IS there an way to combine them?
I think you have a mistake in your click event.
onclick="#Html.CKEditorSubmitButtonUpdateFunction();"
Should read
onclick="CKEditorSubmitButtonUpdateFunction();"
Where CKEditorSubmitButtonUpdateFunction() is the name of your javascript function. There is no need for the appended #Html section.
Edit: and really you shouldnt need an onclick event there? Your form handles the post event action="#Url.Action("Description")"

Resources