Sencha Touch Toggle Button - event-handling

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,
}

Related

Leaflet-routing-machine: Is there a way to load waypoints if they have been saved in some kind of data store?

I followed this great tutorial, add because of it was able to add it to my routing machine; However, I'd like to save the waypoints in local-storage and load them when needed.
I tried this when creating my Routing Machine:
if (map && !this.control) {
this.control = L.Routing.control({
collapsible: true,
show: false,
position: 'bottomleft',
lineOptions: {
styles: [{ color: 'chartreuse', opacity: 1, weight: 5 }]
},
waypoints: [null], //<--- I set the waypoints to null
createMarker: function(i, wp, nWps) {
if (i === 0) {
return L.marker(wp.latLng, {
icon: startIcon,
draggable: true
});
}
if (i === nWps - 1) {
return L.marker(wp.latLng, {
icon: endIcon,
draggable: true
});
}
}
})
.on('routingstart', this.handleLoader.bind(this))
.on('routeselected', function(e) {
var route = e.route;
})
.on('routesfound routingerror', this.handleLoader.bind(this));
And then in the initial listeners for the click events for the start and destination events:
map.on(
'click',
function(e) {
var container = L.DomUtil.create('div'),
startBtn = createButton('Start from this location', container),
destBtn = createButton('Go to this location', container);
function createMarkerHelper(marker) {
setUserMarkers(marker);
}
L.popup()
.setContent(container)
.setLatLng(e.latlng)
.openOn(map);
L.DomEvent.on(
startBtn,
'click',
function() {
var wayPointStart = this.control.getWaypoints()[0].latLng;
if (wayPointStart != null && userMarkers[0] !== undefined) {
this.control.spliceWaypoints(0, 1, userMarkers[0]);
} else {
this.control.spliceWaypoints(0, 1, e.latlng);
createMarkerHelper(e.latlng);
}
map.closePopup();
}.bind(this)
);
L.DomEvent.on(
destBtn,
'click',
function() {
var wapPointDestination = this.control.getWaypoints()[1].latLng;
if (wapPointDestination != null && userMarkers[1] !== undefined) {
this.control.spliceWaypoints(
this.control.getWaypoints().length - 1,
1,
userMarkers[1]
);
} else {
this.control.spliceWaypoints(
this.control.getWaypoints().length - 1,
1,
e.latlng
);
createMarkerHelper(e.latlng);
}
map.closePopup();
}.bind(this)
);
}.bind(this)
);
So this is what I tried for when one starting click event:
function() {
var wayPointStart = this.control.getWaypoints()[0].latLng;
if (wayPointStart != null && userMarkers[0] !== undefined) {
this.control.spliceWaypoints(0, 1, userMarkers[0]);
} else {
this.control.spliceWaypoints(0, 1, e.latlng);
createMarkerHelper(e.latlng);
}
map.closePopup();
}.bind(this)
So essentially I am using the getWaypoints method to check if the waypoint is null, (it would be during a fresh start) and checking if any Markers are in local storage if that conditional is true it would naturally load the markers. If not true it would just set it like normal.
Then later Leaflet has a update function, which you can use to see if props change:
updateLeafletElement(fromProps, toProps) {
var start =
toProps.userMarkers[0] !== undefined &&
this.control.getWaypoints()[1].latLng != null
? toProps.userMarkers[0]
: null,
destination =
toProps.userMarkers[1] !== undefined &&
this.control.getWaypoints()[1].latLng != null
? toProps.userMarkers[1]
: null;
this.control.spliceWaypoints(0, 1, start);
this.control.spliceWaypoints(this.control.getWaypoints().length - 1, 1, destination);
if (toProps.removeRoutingMachine !== false) {
this.control.setWaypoints([]);
}
}
My thinking is this would always ensure the markers are always being updated. But it hasn't worked.
Any ideas? Thanks in advance!

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

Sweet alert go back in 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 &rAarr;',
cancelButtonText: '&lAarr; 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))
}

Change props value in vuejs2

I am new in vuejs2 development. I am working in a modal development. I kept the modal body code in a component and displaying that modal in another component. I have below code in modal body component.
<script>
import SemanticModal from 'vue-ya-semantic-modal'
export default {
components: { SemanticModal: SemanticModal() },
name: 'ModalBody',
props: ['active1',],
data() {
return {
visible: false
}
},
methods: {
close() {
this.$emit('sendValue', false); //this is working
this.visible = false
},
open () {
this.visible = true
},
},
watch: {
active1 () {
if (this.active1 && !this.visible) this.open()
else if (!this.active1 && this.visible) this.close()
},
},
directives: {
'click-outside': {
bind: function(el, binding, vNode) {
el.onclick = function(e) {
var modal = document.getElementsByClassName("modal");
el.addEventListener('click', function (event) {
if (!modal[0].contains(event.target)) {
vNode.context.$emit('sendValue', false); //this is not working
this.visible = false
}
})
}
}
}
}
}
I am calling that model (child) component in parent component like below
<modal-body :active1="active1" #sendValue="active1 = $event"></modal-body>
I need to change the below props active1 value to false from child to parent component.
You are handling click event by using directives.
According to your requirement , clickoutside directive should emit sendValue event from child to parent. But i feel like your code has some complications.
The proper code to accomplish your scenario is below
directives: {
'clickoutside': {
bind: function(el, binding, vNode) {
el.onclick = function(e) {
console.log("binding clicked");
vNode.context.$emit('sendValue', false);
}
}
}
}
if your objective is to use click event you can use #click binding to accomplish the same

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