I have created a linkbar with two labels. Now, I need to keep a track of the label clicks.
10
100
i.e. If in the beginning "First" is clicked, the details will be displayed. After that, if without submitting the details, "Second" is clicked then an alert message should come to inform the user that "First is still in progress, do you want to cancel and begin Second operation". Vice-versa for Second to First transition. I need to know how to write events to keep track of which button clicked.
maybe....
var inProgress:Boolean = false;
var clickedButton:Button;
private function clickButtonHandler(event:MouseEvent):void{
if(clickedButton != null){
if(clickedButton != event.currentTarget && inProgress){
//handle alert
}
}
else{
clickedButton = event.currentTarget;
}
inProgress = true;
}
private function sumbitDetailsHandler(event:Event):void{
inProgress = false;
clickedButton = null;
}
Related
I am trying to make a program that stores my button digital input so that I don't have to keep holding the button for it to work.
The algorithm I am trying to develop is when the button is pressed, it it executes the servoMomvement() function then increments count by one. If count is even then program runs, but then if the button is pressed again it will not be even and would stop working.
void loop() {
while(true){
int count = 0;
bool isEven = count%2;
bool condition = digitalRead(4);
if(condition == true && isEven == false){
servoMovement();
count++;
}
}
}
It is not working as intended. I still have to hold to push button for it to not stop executing.
You can use timer to incremenet count by one.This timer function check periodically button. And when you press it will work as you want. But first of all you have to know timers ability and capacity.
The problem is that the loop method is executed in a loop (like one could guess by the name of the method...) and therefore it's checked in every loop whether the button is pressed.
Because in your if statement it says condition == true && ... this will only be true if the condition is true (the button is pressed).
If I understood your question correctly you want to have some kind of start-/stop-button. If so you could try like this:
//global variable run
bool run;
void setup() {
run = false;
}
void loop() {
while(true){
bool condition = digitalRead(4);
if (condition) {
run = !run;//switch the state of the run variable
delay(50);//some delay to debounce the button; see https://www.brainy-bits.com/arduino-switch-debounce/ for more information
}
if(run){
servoMovement();
}
}
}
I have a quite simple solution for that.
You can compare the actual buttonstate with the buttonstate the "round" before.
bool Button = false;
bool ButtonBefore = false;
bool help = false;
void loop()
{
Button = digitalRead(ButtonPin);
if(Button > ButtonBefore) help = !help;
if(help) { do stuff; }
ButtonBefore = Button;
}
When you press the button, "Button" becomes true while "ButtonBefore" is still false. So "Button" is bigger than "ButtonBefore" so "help" changes to true. In the next cycle "ButtonBefore" is even to "Button" so "help" won't change its state. When the button is released, "ButtonBefore" is bigger than "Button" so it "help" won't change too. So the state from "help" is changed when the button is pressed.
I hope I could help you with this.
Using FullCalendar is there a way to change the event property of another event on the same day as the event that was clicked? I have 2 events on each day and when event A changes I want to change the property of event B. Any ideas?
here's how it worked:
if (boEventClicked.type === "Present") {
//restore UOC event to editable when attendance event is set to 'Present'
var aDate = moment(boEventClicked.start, "MM/DD/YYYY");
$.each($('#calendar').fullCalendar('clientEvents'),
function (idx, eventitem) {
var uDate = moment(eventitem.start, "MM/DD/YYYY");
if ((moment(uDate).isSame(aDate)) && eventitem.type === 'UOC') {
eventitem.readonly = false;
$('#calendar').fullCalendar('updateEvent', eventitem);
}
});
return;
}
I'm a complete beginner regarding the Full Calendar, so apologies for a possible simple question.
I am trying to revert a drop from an External Event. If I use the revertFunc(), the event snaps back to it's original position in the list but the event is still on the calendar until it is refreshed. Ideally I would like it to disappear as soon as the dialog box is closed. This is the code
drop: function(date, jsEvent, ui, resourceId)
{
var tag = $(this).data('event').tag;
var eventDate = $(this).data('event').projectDate;
var calDate = date.format();
if (tag == PSTag)
{
if(eventDate != calDate)
{
alert('You must drop the event on the correct date');
revertFunc();
return;
}
var eventObjectId = $(this).data('event').schWork;
}
if (tag == WOTag)
{
var eventObjectId = $(this).data('event').workorder;
}
var title = $(this).data('event').title;
alert(tag);
updateCalendarEvent(eventObjectId, date.format(), resourceId, tag, title);
if (tag != PHTag)
{
$(this).remove();
}
setupDraggableEvents();
}
Many thanks for any assistance
I know this is probably not the most performant code possible, but if anyone can help I'd really appreciate that.
I'm working on a web-application that's supposed to locate the user's position with the google maps api. For this I created an UI control that starts the tracking of the user's current position and starts a timeout function that should update the position of the user. Everything works fine, but I testet the app when moving around and the geolocation doesn't change with the timeout, it always just shows the position of the first loop. I have to click on the UI control again to update the position.
These are the functions I adapted from the Google developer sites:
The function to detect the position:
//locate the user via GPS by checking geopositioning
function locateUser(geoLoc) {
var geoSuccess = function(position, map) {
startPos = position;
userLat = startPos.coords.latitude;
userLon = startPos.coords.longitude;
geoLoc = {lat : userLat ,lng : userLon};
};
var geoError = function(error, map) {
geoLoc = null;
//console.log('Error occurred. Error code: ' + error.code);
// error.code can be:
// 0: unknown error
// 1: permission denied
// 2: position unavailable (error response from location provider)
// 3: timed out
};
navigator.geolocation.getCurrentPosition(geoSuccess, geoError);
};
locateUser(geoLoc);
I'm using the variable "geoLoc" to get latitude and longitude within the map api.
This is the function that is called by a click on the UI-control and that starts the timeout:
//set the marker for the current position to the geolocation, when geolocation is possible
function setUserPosition(map, geoLoc, controlUI) {
//get the geolocation
locateUser(geoLoc);
//check if the position marker for the user position is already attached
if (positionSet == false) {
//if the position marker is not attached (first time user hits the UI control), generate and attach it nad notify the user that it's position is tracked
positionSet = true;
var userpos = {
url: "https://myhost.com/mygraphic.png", // url
scaledSize: new google.maps.Size(45,45), // scaled size
origin: new google.maps.Point(0,0), // origin
anchor: new google.maps.Point(23,23) // anchor
};
positionMarker = new google.maps.Marker({
position: geoLoc,
map: map,
zIndex: 100,
icon: userpos
});
}
//Check if geolocation is possible.
//If geolocation is not possible, hide the location marker and change the UI control's state back to default, but try again in three seconds.
if(geoLoc == null) {
controlUI.style.backgroundColor = '#4485F8';
controlUI.style.backgroundImage = "url('https://myhost.com/oldbackgroundimage.png')";
moveControl = false;
} else {
//If geolocation is possible, make the position marker visible, set it to the located position and cahnge the UI's state to "active".
posMark = positionMarker;
posMark.setPosition(geoLoc);
controlUI.style.backgroundColor = '#eeeef4';
controlUI.style.backgroundImage = "url('https://myhost.com/newbackgroundimage.png')";
moveControl = true;
}
map.panTo(geoLoc);
//check if the user hit the button to start the positiontracking and loop the function if so
if(moveControl == true) {
timeoutControl = setTimeout(function(){setUserPosition(map, geoLoc, controlUI)}, 3000);
} else if(moveControl == false) {
clearTimeout(timeoutControl);
}
}
And this is the function for the UI-control within the init-map function:
controlUI.addEventListener('click', function() {
//check if the user tapped the UI to locate the current position
if(moveControl == false) {
moveControl = true;
locateUser();
//if geolocation is not possible, open an alert to notify the user
if(geoLoc == null) {
alert("No geolocation :(");
} else {
//if geolocation is possible, set the UI control to the "active" state and start the interval to locate the user permanently (every three seconds)
controlUI.style.backgroundColor = '#eeeef4';
controlUI.style.backgroundImage = "url('https://myhost.com/newbackgroundimage.png')";
setUserPosition(map, geoLoc, controlUI);
//Show the Position marker
posMark.setMap(map);
}
//if the user has tapped the UI control and is in "location-mode" this tap stops the location mode and sets everything back into default state
} else if(moveControl == true) {
clearTimeout(timeoutControl);
moveControl = false;
controlUI.style.backgroundColor = '#4485F8';
controlUI.style.backgroundImage = "url('https://myhost.com/oldbackgroundimage.png')";
//Hide the Position marker
posMark.setMap(null);
}
});
I ran the script with an alert to display geoLoc within the geoSucess function of the locateUser function and it gets executed every time the timeout runs over the code and always fires geoLoc with data, but always only the position the user had when he first clicked the UI control.
Can anybody help and does know why the position is not updated within the timeout or maybe know how it would be updated?
Thanks a lot & kind regards,
Philipp
Update:
I have just found the solution. The following function works (remove the else part):
function confirmSubmit() {
if (Page_ClientValidate("Group1")) {
return window.confirm("Are you sure to submit the form?");
}
}
But I am wondering why it doesn't work when I add the else part.
Question:
I want to have a confirm dialog after user fills in all the data in the form.
I set onclientclick="return confirmSubmit()" in the submit button.
function confirmSubmit() {
if (Page_ClientValidate("Group1")) {
return window.confirm("Are you sure to submit the form?");
} else {
return false;
}
}
If Page_ClientValidate("Group1") returns false, the dropdownlist doesn't cause postback after I first select the item, and the postback only occurs when I select the dropdownlist second time.
What's the problem?
After Page_ClientValidate is called, the variable Page_BlockSubmit gets set to true, which blocks the autopost back. Page_BlockSubmit was getting reset to false on the second click, for what reasons I still don't fully understand. I'm looking more into this, but I have a solution and I'm under the gun so I'm rolling with it....
Just add below code in the code block which executes if Page is not valid.
Page_BlockSubmit = false;
e.g.
function ValidatePage()
{
flag = true;
if (typeof (Page_ClientValidate) == 'function')
{
Page_ClientValidate();
}
if (!Page_IsValid)
{
alert('All the * marked fields are mandatory.');
flag = false;
Page_BlockSubmit = false;
}
else
{
flag = confirm('Are you sure you have filled the form completely? Click OK to confirm or CANCEL to edit this form.');
}
return flag;
}
I have just found the solution. The following function works (remove the else part):
function confirmSubmit() {
if (Page_ClientValidate("Group1")) {
return window.confirm("Are you sure to submit the form?");
}
}