Sweet alert go back in queue - queue

I have came up with a problem of going back in queue in sweet alert.
The code shows one big swal which on confirm shows user swal queue with three options. I need it to go to the first step of queue on cancel button.
I have found a solution with async function, but it is not working in my case (or I have made some mistake. ;) - https://jsfiddle.net/ad3quksn/252/ )
$("#ZKARobimy").click(function () {
swal({
title: "First decidable swal",
allowOutsideClick: false,
width: '70%',
showCancelButton: true,
showConfirmButton: true,
confirmButtonText: 'Go to yes function',
cancelButtonText: 'Go to no function',,
}).then((result) => {
if (result.value) //pressed confirm button
swal.mixin({
confirmButtonText: 'next step ⇛',
cancelButtonText: '⇚ back to settings',
showCancelButton: true,
reverseButtons: true,
progressSteps: ['settings', 'verify', 'ending'],
width: '70%',
allowOutsideClick: false,
}).queue([
{
title: "First in queue - settings",
html: document.getElementById("doingZKAIt").innerHTML,
onOpen: () => {
generujSMSzkaIT();
}, onClose: function (dismiss) {
if (dismiss == 'cancel') {
console.log("first in queue " + dismiss)
$("#ZKARobimy").click();
swal.clickConfirm(); //here i wanted to click confirm button in first swal - before queue
generujSMSzkaIT();
swal.close();
}
console.log("outside if - onclose first in queue")
}
},'swal with back to first one in queue', 'swal without back button'
]), function (dismiss) { //tried to set function for the swal.mixin on cancel button, but it is not working the way i want it to.
if( dismiss == 'cancel')
{
console.log("swal.mixin cancel " + dismiss)
$("#ZKARobimy").click();
swal.clickConfirm();
}
}
} else if (//pressed cancel button
result.dismiss === swal.DismissReason.cancel
) {
swal(
'Cancelled',
'Your imaginary file is safe :)',
'error'
)
}
})
})
Is there any other way to go back in swal queue?

This is available in sweetalert2: https://sweetalert2.github.io/recipe-gallery/queue-with-back-button.html
const steps = ['1', '2', '3']
const swalQueueStep = Swal.mixin({
confirmButtonText: 'Forward',
cancelButtonText: 'Back',
progressSteps: steps,
input: 'text',
inputAttributes: {
required: true
},
reverseButtons: true,
validationMessage: 'This field is required'
})
const values = []
let currentStep
for (currentStep = 0; currentStep < steps.length;) {
const result = await swalQueueStep.fire({
title: `Question ${steps[currentStep]}`,
inputValue: values[currentStep],
showCancelButton: currentStep > 0,
currentProgressStep: currentStep
})
if (result.value) {
values[currentStep] = result.value
currentStep++
} else if (result.dismiss === Swal.DismissReason.cancel) {
currentStep--
} else {
break
}
}
if (currentStep === steps.length) {
Swal.fire(JSON.stringify(values))
}

Related

why is the code crashing when using jeditable?

The code crashes when html tags are entered as input when making fields editable by using jeditable.
It opens my custom error page in the text area itself with the error message "A potentially dangerous Request.Form value was detected from the client "
When user tries to normally save new information the call goes to EditData method at Controller but when user enters html tag and tries to save the code crashes and call does not go to EditData at Controller
$('.editArea').editable('../Data/EditData', {
cssclass: 'jeditForm',
tooltip: 'click to edit',
width: '100%',
height: '150',
type: 'textarea',
title: '',
placeholder: 'click to edit',
submit: 'save',
onsubmit: function (settings, original) {
oldValue = original.revert;
},
submitdata: function (value) {
return {
id: $(this).data('id'),
propertyName: $(this).data('propertyname')
}
},
callback: function (value, settings) {
var jsonData = $.parseJSON(value);
if (jsonData.status) {
this.innerText = jsonData.value;
}
else {
alert("not updated");
this.innerText = oldValue;// + "\n" + jsonData.msg;
}
}
});

Ionic 4 ion-action-controller prevent auto close on button click

I am trying to show the list of language available as an Action sheet. But as soon as the language button is pressed the action sheet closes automatically. Is there any possible way to prevent the auto close of ion-action-sheet controller on clicking the ActionsheetButton.
async showChangeLangAlert() {
const actionSheet = await this.actionSheet.create(
{
header: this.translateText('Select language'),
buttons: this.getLanguageInputTypes(),
cssClass: 'confirmation-popup select-lang',
backdropDismiss: true,
mode: 'md'
}
);
actionSheet.present();
actionSheet.onWillDismiss().then(res => {
console.log(res);
event.preventDefault();
});
actionSheet.onDidDismiss().then(res => {
this.langChoosen.next(this.selectedLanguage);
});
}
private getLanguageInputTypes(): ActionSheetButton[] {
if (this.selectedLanguage === undefined) {
this.selectedLanguage = 'en';
}
return [
{
text: this.translateText('English'),
icon: (this.selectedLanguage.toLowerCase() === 'en') ? 'radio-button-on' : 'radio-button-off',
cssClass: (this.selectedLanguage.toLowerCase() === 'en') ? 'active-option' : '',
handler: () => {
this.selectedLanguage = 'en';
}
},
{
text: this.translateText('German'),
icon: (this.selectedLanguage.toLowerCase() === 'de') ? 'radio-button-on' : 'radio-button-off',
cssClass: (this.selectedLanguage.toLowerCase() === 'de') ? 'active-option' : '',
handler: () => {
this.selectedLanguage = 'de';
}
},
{
text: this.translateText('Select'),
icon: 'checkmark-circle',
cssClass: (this.selectedLanguage.toLowerCase() === 'de') ? 'active-option' : '',
handler: () => {
this.setSelectedLanguage();
}
}
];
}
private setSelectedLanguage() {
// close the action-sheet here
}
I want to achieve the manual close of the action-sheet controller, but it closes automatically on clicking any action button. What I am missing or is there any workaround to show the alert window as an action sheet?
the handler: ()=> returns to true after a button is clicked which dismisses the actionsheet. Returning false after the button is clicked in the handler() will keep the actionsheet in place.
handler: ()=>{
// assign selected language
this.selectedLanguage = 'en';
// then return false
return false;
}
backdropDismiss
Description
If true, the action sheet will be dismissed when the backdrop is clicked.
Attribute backdrop-dismiss
Type boolean
Default true
backdropDismiss:false

is it possible to change button's text with $ionicPopup.confirm()?

I'm using $ionicPopup.confirm() but I would like to change "cancel's button" text. Is it possible to do so ?
I'm aware of .show() syntax:
buttons: [
{ text: 'Cancel' }
]
But it does not seem to work with .confirm() ...
Thank 4 the help
At least in the latest release of Ionic (1.0.0) you can do the following:
var confirmPopup = $ionicPopup.confirm({
title: 'Popup title',
template: 'Popup text',
cancelText: 'Custom cancel',
okText: 'Custom ok'
}).then(function(res) {
if (res) {
console.log('confirmed');
}
});
Here is the relative documentation.
UPDATE : on ionic 1.0.0, this is now possible, check here
showConfirm Options :
{
title: '', // String. The title of the popup.
cssClass: '', // String, The custom CSS class name
subTitle: '', // String (optional). The sub-title of the popup.
template: '', // String (optional). The html template to place in the popup body.
templateUrl: '', // String (optional). The URL of an html template to place in the popup body.
cancelText: '', // String (default: 'Cancel'). The text of the Cancel button.
cancelType: '', // String (default: 'button-default'). The type of the Cancel button.
okText: '', // String (default: 'OK'). The text of the OK button.
okType: '', // String (default: 'button-positive'). The type of the OK button.
}
Yes you can do wathever you want, using ionic popup.show and bind the Cancel event.
$ionicPopup.show({
template: msg,
title: titleConfirm,
buttons: [
{ text: "BTN_NO",
onTap:function(e){
return false;
}
},
{ text: "BTN_OK",
onTap:function(e){
return true;
}
},
]
});
After investigation on the ionic popover.confirm function this is
not possible to customize it. The value of popover.confirm are hardcoded line 446
function showConfirm(opts) {
return showPopup(extend({
buttons: [{
text: opts.cancelText || 'Cancel',
type: opts.cancelType || 'button-default',
onTap: function() { return false; }
}, {
text: opts.okText || 'OK',
type: opts.okType || 'button-positive',
onTap: function() { return true; }
}]
}, opts || {}));
}
It's possible to do, you have to use the "type" thing inside the button
buttons: [
{ text: 'Cancel' },
{
text: '<b>Save</b>',
type: 'button-assertive',
onTap: function(e) {
$scope.request_form.abc = "accepted";
}
}
]
in the type part you have to give the class name , and you can change the color of the button.

Jquery datepicker keypress to trigger button

I have a datepicker that is bind to the textbox
MakeDateField: function () {
$(this).not(".dispField").datepicker({ dateFormat: 'dd/mm/yy', changeMonth: true, changeYear: true, yearRange: '-100:+20', onSelect: function () { $(this).blur(); } });
$(this).blur(function () {
$(this).val($.trim($(this).val()));
if (datePickerBlurFix == 0) {
datePickerBlurFix = 1;
if (isValidDate($(this).val()) == false) {
$(this).val(convertDate($(this).val()));
if (dateRegEx.test($(this).val()) == false && $(this).val() != '') {
if ($(this).val() != "today" && $(this).val() != "**No Access**") {
$(this).val('');
msgBox({ Msg: msgDateCheck, Title: applicationName + ' - Error', Width: 300, Type: 'warning' }, function () {
$(this).focus();
datePickerBlurFix = 0;
});
}
}
}
}
datePickerBlurFix = 0;
});
},
My problem is when I press enter, the datepicker will automatic select today date. But it doesn't go in to the following code
$("#<%=txtDateSendFrom.ClientID %>").keypress(function (event) {
if (event.which == 13) {
$("#<%=btnFilter.ClientID %>").trigger("click");
event.preventDefault();
}
});
No matter how hard I press "Enter". I think this is because it has lost focus, but if I add one $(this).focus() in to the datepicker. It also didn't work, plus the window of the datepicker will remain opened.
How can I solve this problem?
Thank You

Sencha Touch Toggle Button

How could you run some action when pushing a toggle button like this:
{
xtype: 'togglefield',
name: 'enableSnd',
label: 'Sound',
value : 1
}
?
Here's an example I'm currently using in an app of mine. I use the "beforechange" function to check and validate some data before I perform the real action in "change".
{
xtype: 'togglefield',
name: 'toggleName',
label: 'My Toggle Field',
listeners: {
beforechange: function (slider, thumb, newValue, oldValue) {
if (oldValue == 0 && newValue == 1) {
// Changing from off to on...validate something?
}
},
change: function (slider, thumb, newValue, oldValue) {
if (oldValue == 0 && newValue == 1) {
// Changing from off to on...do something?
}
else if (oldValue == 1 && newValue == 0)
// Changing from on to off...do something?
}
}
}
Have a look at the official documentation in sencha:
http://dev.sencha.com/deploy/touch/docs/
For a simple button:
var playPauseButton = new Ext.Button({
ui: 'small',
text: 'Play',
listeners: {
tap: function() {
Ext.Ajax.request({
url: '/api/pause',
success: updateStatus,
failure: updateStatus });
}
}
});
For a toggle, event seems to be dragend...
I use the the following code to set an initial value to a togglefield
and to react to changes of the togglefield.
I initially disable the togglefield,
and then use the (unexpected) behaviour that
Sencha Touch fires a change event for this togglefield while initializing it to enable the togglefield.
Note this should work for both true and false as initial values.
If you would like to actually disable the togglefield initially,
you would have to remove the else part.
{
xtype: 'togglefield',
title: 'LightSwitch',
label: 'Switch Lights',
value: false, // initial value
listeners: {
change: function(slider, thumb, newValue, oldValue) {
if (this.isDisabled() == false) { // isEnabled
alert('change Togglefield Event triggered'); // do something
}
else {
this.enable(); // enable togglefield
}
}
},
disabled: true,
}