Jquery Dialog No button - jquery-selectors

My problem is, I have a jquery dialog with buttons yes and no.
What I would like to do is when the user clicks on no, the dialog displays
another content in a hidden class and the user clicks no again it closes the dialog.
I have tried finding solutions to this but cant find any.
This is what I have so far but aint working:
"No": function() {
$("#dialog").html($("#cool"));
if ($("#cool") == true) {
$(this).dialog("close");
}
}

The code written in the question is not clear about the purpose.
Here is my understanding about this.
Initially, The "cool" div is hidden, but has some content which you want to display when the user clicks "No". The next time "No" is clicked, the dialog should be closed.
If this is what is required, then the below code should help.
"No": function() {
if ($("#cool").is(":visible") == true) {
$(this).dialog("close");
} else {
$("#cool").show();
}
}

Related

bootbox confirm dialog box, cancel button is not working

I have a bootbox confirm dialog box. In that, I have some form validation.Validation working fine and as long as validation fails confirm dialog box still opens. But when I click on the cancel button, still it is asking for validation.
bootbox.confirm({
closeButton: true,
message: valid_result,
size: 'large',
title: 'Fill fields with related values',
buttons : {
confirm : { label: '<i class="fa fa-check"></i> Validate'}
},
callback: function () {
var res = getLinkupInformation(ids_string)
if(res == true) {
return true;
} else {
return false;
}
}
});
The validation part is working and if validation passed then only modal was closing. But when user click on the cancel button or close icon still it is asking validation. When I remove return false in call back function in else part then the validation button is not working and when I click on the validate button confirmation dialog box was closing.
Please guide me how to solve this issue?
The callback expects you to supply an argument, like so:
callback: function (result) {
}
If the user cancelled the dialog, either by clicking Cancel or the close (x) button, then result (or whatever you called your argument) will be the value false. You would use that value like this:
callback: function (result) {
if(result) {
/* your code here */
}
}
This is more or less covered in the documentation.

How to prevent ionic keyboard from hiding

How can I prevent ionic keyboard from hiding when I press a specific button in my Ionic 1 app?
This solution doesn't work for me, the keyboard remains open wherever I click.
A possible solution can be found here (the same link sent by Sahil Dhir). I also had this problem and this solution worked for me.
The directive is:
angular.module('msgr').directive('isFocused', function($timeout) {
return {
scope: { trigger: '#isFocused' },
link: function(scope, element) {
scope.$watch('trigger', function(value) {
if(value === "true") {
$timeout(function() {
element[0].focus();
element.on('blur', function() {
element[0].focus();
});
});
}
});
}
};
});
Its usage is:
<input type="text" is-focused="true">
What it basically does is to watch the focus of the input and whenever the input loses focus (when you press a button on the screen outside the keyboard, for example) it rapidly assigns the focus back to it. So the keyboard doesn't have time to hide.
Hope it works for you too!

removeBackView() not working in Ionic?

JS code
console.log('Login Success');
$ionicHistory.removeBackView();
I am trying to stop to get the login view after login. But even I was logged in, if I click on back arrow of the browser, I am getting the login page. But Once I logged in I should get home page if I click on back arrow. .removeBackView() is not working properly. Please help me.
Even $ionicHistory disableBack also not working
I was having this problem. Putting removeBackView() in the next state didn't work. So instead I added this to the previous state, right before $location.path( '/app/myFirstPage' )
$ionicHistory.nextViewOptions( {
disableBack : true
} );
I also face same type of problem so use another concept, I think its help you.
if ($state.current.name == "app.home" || $state.current.name == "login") {
$ionicPopup.confirm({
title: "Confirm",
template: "Want to exit?"
}).then(function (res) {
if (res) {
navigator.app.exitApp();
}
});
} else {
navigator.app.backHistory();
}

Click Anywhere Pop Up

I'm trying to create a popup (new window) that appears when a person clicks anywhere on the page , but the problem is that my script creates a new tab for every click . I created a blogspot account just for test : http://faqetest123.blogspot.al/
what should I do for that ?
(example of a site that is using the popup that im trying to create is :atdhe.so)
Here is my code :
<script type="text/javascript">
document.onclick=function()
{
window.open('http://www.facebook.com');
}
</script>
Thanks
The window.open() function returns a reference to that window. So you should be able to use that reference to navigate to a new URL at a later time. Something like this:
var myPopup;
document.onclick=function()
{
if (!myPopup) {
myPopup = window.open('http://www.facebook.com');
} else if (myPopup.closed) {
myPopup = window.open('http://www.google.com');
} else {
myPopup.location.href = 'http://www.stackoverflow.com';
}
}
Note that this also attempts to check if the user has closed the pop-up and re-opens it.
Edit: Based on your comments below, it looks like I misunderstood. In order to have the popup execute once and then not again, you can simply remove the event handler after processing it. Something like this:
document.onclick=function()
{
window.open('http://www.facebook.com');
document.onclick = null;
}

How to fire place_changed event for Google places auto-complete on Enter key

The click seems to fire the event and set the cookies but pressing enter to submit doesn't set the cookies and instead the page redirects without the cookies.
function locationAuto() {
$('.search-location').focus(function () {
autocomplete = new google.maps.places.Autocomplete(this);
searchbox = this;
google.maps.event.addListener(autocomplete, 'place_changed', function () {
var thisplace = autocomplete.getPlace();
if (thisplace.geometry.location != null) {
$.cookie.raw = true;
$.cookie('location', searchbox.value, { expires: 1 });
$.cookie('geo', thisplace.geometry.location, { expires: 1 });
}
});
});
The .search-location is a class on multiple textboxes.
There is a submit button that takes the values from the cookies and redirects (server side)
Adapted from Jonathan Caulfield's answer:
$('.search-location').keypress(function(e) {
if (e.which == 13) {
google.maps.event.trigger(autocomplete, 'place_changed');
return false;
}
});
I've encountered this problem as well, and came up with a good solution. In my website I wanted to save the autocomplete.getPlace().formatted_address in a hidden input prior to submission. This worked as expected when clicking the form's submit button, but not when pressing the Enter key on the selection in the autocomplete's dropdown menu. My solution was as follows:
$(document).ready(function() {
// Empty the value on page load
$("#formattedAddress").val("");
// variable to indicate whether or not enter has been pressed on the input
var enterPressedInForm = false;
var input = document.getElementById("inputName");
var options = {
componentRestrictions: {country: 'uk'}
};
autocomplete = new google.maps.places.Autocomplete(input, options);
$("#formName").submit(function(e) {
// Only submit the form if information has been stored in our hidden input
return $("#formattedAddress").val().length > 0;
});
$("#inputName").bind("keypress", function(e) {
if(e.keyCode == 13) {
// Note that simply triggering the 'place_changed' event in here would not suffice, as this would just create an object with the name as typed in the input field, and no other information, as that has still not been retrieved at this point.
// We change this variable to indicate that enter has been pressed in our input field
enterPressedInForm = true;
}
});
// This event seems to fire twice when pressing enter on a search result. The first time getPlace() is undefined, and the next time it has the data. This is why the following logic has been added.
google.maps.event.addListener(autocomplete, 'place_changed', function () {
// If getPlace() is not undefined (so if it exists), store the formatted_address (or whatever data is relevant to you) in the hidden input.
if(autocomplete.getPlace() !== undefined) {
$("#formattedAddress").val(autocomplete.getPlace().formatted_address);
}
// If enter has been pressed, submit the form.
if(enterPressedInForm) {
$("#formName").submit();
}
});
});
This solution seems to work well.
Both of the above responses are good answers for the general question of firing a question when the user presses "enter." However - I ran into a more specific problem when using Google Places Autocomplete, which might have been part of the OP's problem. For the place_changed event to do anything useful, the user needs to have selected one of the autocomplete options. If you just trigger 'place_changed', the if () block is skipped and the cookie isn't set.
There's a very good answer to the second part of the question here:
https://stackoverflow.com/a/11703018/1314762
NOTE: amirnissim's answer, not the chosen answer, is the one to use for reasons you'll run into if you have more than one autocomplete input on the same page.
Maybe not the most user friendly solution but you could use JQuery to disable the enter key press.
Something like this...
$('.search-location').keypress(function(e) {
if (e.which == 13) {
return false;
}
});