Just implemented an alert on my Google Spreadsheet App, it works via browser, but it's not working on the Google mobile app.
Below the code I am using:
function showAlert(currentValue) {
var ui = SpreadsheetApp.getUi();
var result = ui.alert(
'WARNING',
'You are modifying the cell with value ' + currentValue + ', do you want to continue?',
ui.ButtonSet.YES_NO);
// Process the user's response.
if (result == ui.Button.YES) {
// User clicked "Yes".
return true;
} else {
// User clicked "No" or X in the title bar.
return false;
}
}
There's any solution to make it work on mobile app too or any other similar solution to warn the user when trying to modify a not empty cell?
Thanks.
Related
I am making in which I want to display alert box and then redirect it to some other page in asp.net
My code is
var s = Convert.ToInt32(Session["id"].ToString());
var q = (from p in db.students
where p.userid == s
select p.sid).SingleOrDefault();
if (q == 0)
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "reg();", true);
}
this is my reg() function
function reg() {
var con = alert('Please Register Your Self Fisrt ..!! Thank you');
window.location = "reg.aspx";
}
My code is working fine but alert box gets disappear after some second without clicking on it because of that user is unable to read alert message
I want to redirect it to reg.aspx but after clicking OK on alert box ..
please help
Firing a confirm box instead of alert will do what you are trying to achieve. You will have the option to redirect conditionally or unconditionally
function reg(){
var con=confirm("You need to register first before proceeding. Redirect to Registration Page");
if(con==true){
window.location = "reg.aspx";
}
else{
//if redirect unconditionally
window.location = "reg.aspx";
}
}
I'm writing an app in javascript and html with phonegap/cordova.
I have this code in javascript:
$('#diario_delete_btn').live('tap',function(e){
var iddb = $(this).find('a').attr('rel');
confirm_diario_delete(iddb);
});
function diario_delete(iddb) {
var db = window.openDatabase("Database", "1.0", "123nozze", 200000);
db.transaction(function(tx){
tx.executeSql('DELETE FROM AgendaItemJDO WHERE id='+iddb);
lastChangeUpdate();
});
$('.diario_row[db_id="'+ iddb +'"]').remove();
$('#popupMenuDiario').popup("close");
}
function confirm_diario_delete(iddb) {
var r = confirm("Confermi l'eliminazione dell'elemento?");
if (r) {
diario_delete(iddb);
} else {
$('#popupMenuDiario').popup("close");
}
}
It seems to work but if I choose "cancel button" (so r = false) n times before I press "confirm button", next time the confirm dialog is displayed 2 times, next time it is displayed 3 times, and so on. I don't know why this behaves this way. The same is if a change the code and I use the Cordova example code for confirm dialog.
Any ideas on what is the problem and how can I solve it?
Thanks!
You should use the native notification which Phonegap supports.
Specifically the .confirm() method taken from link above;
// process the confirmation dialog result
function onConfirm(button) {
alert('You selected button ' + button);
}
// Show a custom confirmation dialog
//
navigator.notification.confirm(
'You are the winner!', // message
onConfirm, // callback to invoke with index of button pressed
'Game Over', // title
'Restart,Exit' // buttonLabels
);
navigator.notification.confirm(
'Are you sure you want to signup ', // message
onConfirm, // callback to invoke with index of button pressed
'SignUp', // title
['yes','no'] // buttonLabels
);
function onConfirm(buttonIndex){
alert('You selected button ' + buttonIndex);
if(buttonIndex==2){
alert('You selected button - no');
}else{
alert('You selected button - yes');
}
}
This is my popup.js in the chrome extension:
function getlink(){
console.log(document.getElementById("linkify").value);
if(document.getElementById("linkify").value == "on")
{
localStorage.setItem("linkify",false);
document.getElementById("linkify").innerHTML = "Get links - off";
document.getElementById("linkify").value = "off";
console.log(document.getElementById("linkify").value);
chrome.extension.sendRequest({ msg: "linkify"});
}
else if(document.getElementById("linkify").value == "off")
{
localStorage.setItem("linkify",true);
console.log("Hello!");
document.getElementById("linkify").innerHTML = "Get links - on";
document.getElementById("linkify").value = "on";
chrome.extension.sendRequest({ msg: "linkify"});
}
}
$(document).ready(function (){
if(localStorage.getItem("linkify"))
{
document.getElementById("linkify").innerHTML = "Get links - on";
document.getElementById("linkify").value = "on";
}
$("#linkify").click(function() {
getlink();
});
});
Basically, the functionality that I want is this: a button in the extension which can be toggled on or off. When toggled, its text changes and so does the value stored in localStorage.
Though, the toggle works fine, this is the bug that happens:
If I switch off the button, that is turn it into get links off and exit the popup. And then open the popup again, the button state is back "on". It is not maintaining its state.
You problem is how you are using local storage. Local storage stores everything as a string.
So basically:
localStorage.setItem("foo", false)
localStorage.getItem("foo") // returns "false"
if(localStorage.getItem("foo")) {
console.log("bar")
} else {
console.log("bing")
}
// Logs bar
Use if(JSON.parse(localStorage.getItem("linkify")))
I need to change the back button functionality of my phonegap project, which I've succeeded in doing without any problem. The only issue now, is that I need to further change the functionality based on if the user has a certain field selected.
Basically, if the user has clicked in a field with the id of "date-selector1", I need to completely disable the back button.
I was attempting to use document.activeElement, but it only returns the type of the element (input in this case), but I still want the functionality to work when they are in a general input, but not when they are in an input of a specific id.
EDIT
I tried all of the suggestions below, and have ended up with the following code, but still no success.
function pluginDeviceReady() {
document.addEventListener("backbutton", onBackKeyDown, false);
}
function onBackKeyDown() {
var sElement = document.activeElement;
var isBadElement = false;
var eList = ['procedure-date', 'immunization-date', 'lab-test-done', 'condition-onset', 'condition-resolution', 'medication-start-date', 'medication-stop-date', 'reaction-date'];
console.log("[[ACTIVE ELEMENT: --> " + document.activeElement + "]]");
for (var i = 0;i < eList.length - 1;i++) {
if (sElement == $(eList[i])[0]) {
isBadElement = true;
}
}
if (isBadElement) {
console.log('Back button not allowed here');
} else if ($.mobile.activePage.is('#main') || $.mobile.activePage.is('#family') || $.mobile.activePage.is('#login')) {
navigator.app.exitApp();
} else {
navigator.app.backHistory();
}
}
if you're listening for the back button you can add this if statement:
if (document.activeElement == $("#date-selector1")[0]) {
/*disable button here, return false etc...*/
}
or even better (Thanks to Jonathan Sampson)
if (document.activeElement.id === "date-selector1") {
/*disable button here, return false etc...*/
}
You can have a flag set when a user clicks on a field or you can have a click event (or any other type of event) when a user clicks on the field that should disable the back button.
From the documentation it looks like for the specific page that the backbuton is conditional on you can drop back-btn=true removing that back button.
http://jquerymobile.com/test/docs/toolbars/docs-headers.html
If you need complex conditional functionality you can just create your own button in the header or footer, style it using jquery-mobile widgets and implement your own click functionality.
I have added some javascript in html page for input validation.same page is working correct in IE and chrome but in mozila its not working.The problem is when user inputs invalid data its supposed to show alert msg box and when user clicks OK it should return false to form...BUT mozila is not waiting for alert box it just shows alert box for 5-6 sec and then goes to next page defined in form action="nextpage.php"
function validate_form(thisform)
{
with (thisform)
{
if (validate_required(oldpassword, "<b>Error: </b>Please enter the Old Password!") == false)
{ changeColor("oldpassword"); return false; }
else if (valid_length(newpassword, "<b>Error: </b>Please enter the New Password!!") == false)
{newpassword.value=""; changeColor("newpassword"); return false; }
else if (valid_length(cnfpassword, "<b>Error: </b>Please enter the Confirm Password!!") == false)
{cnfpassword.value=""; changeColor("cnfpassword"); return false; }
else if (document.getElementById('newpassword').value != document.getElementById('cnfpassword').value)
{changeColor("newpassword");cool.error("<b>Error: </b>Passwords entered are not same!");
newpassword.value="";cnfpassword.value="";return false;}
}
}function validate_required(field, alerttxt)
{
with (field)
{
if (value == null || value == "")
{
cool.error(alerttxt);return false;
}
else
{
return true;
}
}
}
cool.error is nothing but CSS nd Js for alert box.I thing there is not any problem in my code weather problem is in some browser settings.Is it so??? because it is working fine in IE and Chrome.
You're using a non-standard IE-only behavior that creates global variables for every element with an ID.
To fix it, add a global variable for each element that you use:
var oldpassword = document.getElementById("oldpassword");
Also, you should never use Javascript's with block.
It is very different from VB's with block, and should not be used unless you truly understand its pitfalls and shortcomings. It will also slow down your code.
You could also use some javascript library to get past browser issues. I'm rooting for jQuery.