In my application after tapping on a one button it gives and alert.There are two button on alert window: 1. Cancel 2. Ok
I have tried to tap on OK by using the solution given on the forum but it dosen't work.
UIATarget.onAlert = function onAlert(alert) {
var title = alert.name();
UIALogger.logWarning("Alert with title '" + title + "' encountered!");
if (title == "Attention")
{
alert.buttons()["OK"].tap();
return true; // bypass default handler
}
return false; // use default handler
}
Function for handling alert dosen't called.Can anyone help me on this issue?
Thanks in advance.
UIATarget.onAlert = function onAlert(alert)
{
UIATarget.localTarget().delay(1);
UIALogger.logMessage("alertShown");
target.captureScreenWithName("AlertCaptured");
return true;
}
app.alert().buttons()["OK"].tap();
My solution to this problem was to add an one second delay after the function that handles the alert. You can not end your script with that function.
UIATarget.onAlert = function onAlert(alert) {
var title = alert.name();
UIALogger.logWarning("Alert with title '" + title + "' encountered.");
if (title == "Are you sure you want to delete this?") {
alert.buttons()["Delete"].tap();
return true; //alert handled, so bypass the default handler
}
return false;
}
target.delay(1);
Related
i am complete newbie in jquery/js
I am trying to create web interface for my robotcar and check for multiple keypresses, whenever i release all keys robotcar would stop.
http://jsfiddle.net/gFcuU/1105/
var keys = {};
$(document).keydown(function (e) {
keys[e.which] = true;
keypr();
printKeys();
});
$(document).keyup(function (e) {
delete keys[e.which];
printKeys();
});
function printKeys() {
var html = '';
for (var i in keys) {
if (!keys.hasOwnProperty(i)) continue;
html += '<p>' + i + '</p>';
}
$('#out').html(html);
}
function keypr(){
if (keys[87] && keys[68] == true){
alert('shit works');
}
}
Multiple keypress detection works but if i press W+D stated in function keypr it stops working properly.
Thanks for help
Dude. Your code is working perfectly, but when you do the alert while detecting keypresses, it gets stuck.
Just remove the alert and everything is gonna be fine. if you don't wanna remove the alert i guess you have to remove the object, before displaying the alert.
function keypr(){
if (keys[87] && keys[68] == true){
delete keys[68];
delete keys[87];
alert('shit works');
}
I want to assign a click handler for button in the page load function. I then want to handle the actual click of the button at a later time with the following code snippet:
$("#finish").off('click').on('click', function () {
var sku = $("#productSKU").val();
var name = $("#productName").val();
var affiliateId = $("#AffiliateID").val();
var Errors = "";
var category = null;
var defaultName = $('#defaultImgName').val();
if ($("#childCategories_" + categoryLevel).length == 0) {
category = $("#categoryList").val();
}
else if ($("#childCategories_" + categoryLevel).val() == 0) {
category = null;
}
else {
category = $("#childCategories_" + categoryLevel).val();
}
if (!sku) {
Errors += "<li> You can not add a product without an Item Code</li>";
}
if (!name) {
Errors += "<li> You can not add a product without a Name</li>";
}
if (!category) {
Errors += "<li> You can not add a product without a Category</li>";
}
if (Errors != "") {
cua({ text: Errors, type: 'danger' })
}
else {
data.formData = { productName: name, productSKU: sku, affiliateID: affiliateId, categoryID: category, defaultImgName: defaultName }
data.submit();
}
});
How do I assign the click event handler in the page load, and then trigger the actual event of the click later on?
Reason for this is it's causing errors where the button is unresponsive if an image is not uploaded, which I found to be caused by an event handling problem.
$(document).ready(function(){
$("#finish").on('click', yourfunctionhere)
});
You can put your code in a seperate function, so if you want to turn it off, then on again you can do it with just 1 line of code.
$("#finish").on('click', yourfunctionhere)
To execute the function you can trigger the click (when the handler is on):
$("#finish").trigger('click');
(thanks #putvande for reminding)
I have an asp page in which I add dynamically a control I created (several times). In that control I have textbox for password and username and a revert button.
I use this javascript code in that control and it fails:
function HandlePasswordChanged() {
document.getElementById("<%=btnRevert.ClientID %>").disabled = false;
}
function HandleUserChanged() {
document.getElementById("<%=btnRevert.ClientID %>").disabled = false;
document.getElementById("<%=txtPassword.ClientID %>").disabled = false;
}
function btnRevertClick() {
document.getElementById("<%=btnRevert.ClientID %>").disabled = true;
document.getElementById("<%=txtPassword.ClientID %>").disabled = true;
document.getElementById("<%=txtUsername.ClientID %>").value = document.getElementById("<%=systemAccount.ClientID %>").value;
document.getElementById("<%=txtPassword.ClientID %>").value = "";
}
what it does is when I press the revert button on one control it disables the textbox on the other control - getelement fails to find the correct one.
How can I fix this?
If you are working on .net 4.0:
You can set ClientIDMode="Static" for your dynamically added controls. Also, you have to make sure you set unique ids for your controls.
I managed to find the solution.
The problem was that every time I added the acsx control with the javascript code it added multiple functions with the same name but the inside was different. when one control wanted to call its "own" function it just used the first one since they were all named the same.
My solution was to change the function from this:
function HandleUserChanged() {
document.getElementById("<%=btnRevert.ClientID %>").disabled = false;
document.getElementById("<%=txtPassword.ClientID %>").disabled = false;
}
to this:
function HandleUserChanged(btnRevertId, txtPasswordId, cellPasswordId) {
document.getElementById(btnRevertId).disabled = false;
document.getElementById(txtPasswordId).disabled = false;
}
and then in the c# code I add this:
txtUsername.Attributes.Add("onchange", "HandleUserChanged(\"" + btnRevert.ClientID + "\", \"" + txtPassword.ClientID + "\", \"" + cellPassword.ClientID + "\")");
This way each control know exactly which controls belong to him and sends the correct parameters to the function.
I am trying to validate date using jquery. If user entered invalid date, then it should set focus in same control. I have written below code it works fine in all browsers but in Mozilla its not working.
JavaScript Code:
function CheckDate(txt) {
var isValid = false;
var txtDate = $('input[id$=' + txt + ']').val();
if (txtDate.length == 0) {
isValid = true;
}
else {
if (isDate(txtDate)) {
isValid = true;
}
else {
isValid = false;
$('#' + txt).focus();
}
}
//alert(txtControl);
}
I am calling this function on onBlur event of textbox.
I didnt got any solution for this. If anybody knows than please help me.
Try .trigger('focus') instead of simple .focus()
In your code, I feel that the selector has issues. We need to see the value of txt. So can you change your this part of code:
$('#' + txt).focus();
To:
$('input[id$=' + txt + ']').focus();
You can use this code
$('#' + txt).attr('value');
and use this
$('#' + txt).focus();
it works with focus inside setTimeOut : http://www.echoknowledge.com/javascript-focus-is-not-working-in-firefox/
i am having a Alert function as below :
UIATarget.onAlert = function onAlert(alert)
{
var title = alert.name();
UIALogger.logWarning("Alert with title '" + title + "' encountered!");
if (title == "Installation for this product is actually free with delivery - you will not be charged for installation.")
{
alert.buttons()["OK"].tap();
return true; // bypass default handler
}
return false; // use default handler
}
here i want execute a condition, if the alert message appears i want to execute
mainWindowTarget.scrollViews()[0].scrollToElementWithName("Add to cart");
var AddButton = mainWindowTarget.scrollViews()[0].buttons().firstWithName("Add to cart").tap();
So once the alert message comes the above two line should be executed
can somebody help on this
Alert function will handle the alert which are popped up and it is automatically called. However to use scroll view and tap over it you first have to dismiss the alert pop and then come back to the screen having scroll view. But its good to experiment the same..[]