Alert dialog not working in Lua - lua

I am using Lua with Gideros and having alert box to show up when back button is pressed.According to Gideros documentation, when first button is pressed, it returns index 1 but it does not really seem to work this way.I tested the app on my android phone.I realized the oncomplete function is not getting called at all, since I tried using a print statement and even it was not executed, so any idea why is is not getting called?
local function onKeyDown(event)
if event.keyCode == KeyCode.BACK then
local alertDialog = AlertDialog.new("Confirmation", "Are you sure you want to exit?", "Cancel", "Yes")
alertDialog:show()
stage:addEventListener(Event.COMPLETE, oncomplete)
end
end
function oncomplete(e)
if e.buttonIndex == 1 then
stage:addEventListener(Event.APPLICATION_SUSPEND, suspend)
application: exit()
end
end
function suspend()
application: exit()
end
-- key events are dispatched to all Sprite instances on the scene tree (similar to mouse and touch events)
stage:addEventListener(Event.KEY_DOWN, onKeyDown)

As per the conversation the issue was that the event listener for the alert box close event was being attached to the stage instead of the alert dialog.
stage:addEventListener(Event.COMPLETE, oncomplete)
instead of
alertDialog:addEventListener(Event.COMPLETE, oncomplete)

Related

How to get text from alertbox in spectron-mocha-webdiverio

I am testing my electron app using spectron.
I am trying to get text from alertbox but getting an error.
I want to get the text from alert and if that is expected then accept it.
Test :
it('Check alert message', function() {
return this.app.client
.waitForExist('#associates', 20000).should.eventually.equal(true)
.click('#pq-associates')
.click('#submit-selection')
.alertText().should.eventually.equal("You have to select any one")
.should.eventually.exist
});
I am getting the following error
no alert open
Error: An attempt was made to operate on a modal dialog when one was not open.
But I can see the alert.
As discussed with the WebDriverio community it is difficult to handle the default alert() function. They suggested to implement my own alert() like function. So using https://github.com/limonte/sweetalert2 I implemented my own alert and the test is working fine.
Community discussion : https://gitter.im/webdriverio/webdriverio/archives/2017/10/04
Spectron issue : https://github.com/electron/spectron/issues/23

Throttling Search with UISearchController

I have an Xamarin.iOS app which does some search on a long list that takes some time.I would like to introduce some throttling instead of searching for every single key stroke . Any idea ?
You can use Reactive extensions, asuming that you use C# style events instead of iOS Delegates.
Here is a bare bone sample code with UITextView:
var observable = Observable.FromEventPattern<EventArgs>
(
//Those are actions used to subscribe and unsubscribe for the event
eventHandler => TextView.Changed += eventHandler,
eventHandler => TextView.Changed -= eventHandler
)
.Sample(TimeSpan.FromMilliseconds(500)) //This will sample every 500 to check if the event has been raised
.Select(e => e.Sender as UITextView) //This is used so we can directly use the TextView in the subscribe method
observable.Subscribe(textView =>
{
//This will be executed if the event was raised the last 500 miliseconds
//This may not run on the UI thread
InvokeOnMainThread(() => Label.Text = textView.Text);
});
This will Sample the text every 500 miliseconds and if the event was rased at least once it will call the Action in the Subscribe method. Or you can use .Throttle instead of .Sample which will be called if the event was not raised for the interval which will be 500 miliseconds after the user stopped typing.
The cool thing is that you can filter the text with a:
.Where(textView => !String.IsNullOrWhiteSpace(textView.Text) || !IsCompleteNonSense(textView.Text));
after the Select method so it wont raise the event if the text is empty or if you want to make some other checks.
I came across this watching a presentation from Xamarin Evolve 2016 here is a link to the video. And here is a link to the source code.
The samples are on Xamarin.Forms but they will give you a good starting point.

Clojure and JavaFX 2.0 -- How to access element's ID from clojure callback function

Following the JavaFX Tutorial here: http://docs.oracle.com/javafx/2/get_started/fxml_tutorial.htm, trying to make it run in Clojure. For now I'm just doing lein run after setting up :aot :all and stuff with (:gen-class) etc. It took a few days of figuring out, but now it seems to be mostly working.
In src/jfxtwo/ClojureExampleController.clj:
(defn -handleSubmitButtonAction [^ActionEvent event]
(let [actiontarget (Text.)]
(println "event button pressed")
(println "Event instance:" event)
(println "Event class:" (class event))
(.setText actiontarget "Sign in button pressed...")))
In resources/fxml_example.fxml:
<GridPane fx:controller= "jfxtwo.ClojureExampleController"
xmlns:fx= "http://javafx.com/fxml"
alignment= "center" hgap= "10" vgap= "10"
styleClass= "root" >
...
<Button text= "Sign In"
onAction= "#handleSubmitButtonAction" />
...
<Text fx:id= "actiontarget"
GridPane.columnIndex= "1" GridPane.rowIndex= "6" />
...
I have my clojure code able to read the fxml and css file to generate the proper GUI. When I press the button I can see the event handler being called, but I don't know how to access the Text I want to change, or the ActionEvent instance that is associated with the button press. I tried (println event) and (println (class event)) expecting to see something about an ActionEvent instance, but this only results in showing me that for whatever reason the callback function thinks the event is a ClojureExampleController, even though the type hint says it should be an ActionEvent:
event button pressed
Event instance: #<ClojureExampleController jfxtwo.ClojureExampleController#3e61061d>
Event class: jfxtwo.ClojureExampleController
The Java code to do this looks like this:
public class JFXAppSampleController {
#FXML private Text actiontarget;
#FXML protected void handleSubmitButtonAction(ActionEvent event) {
actiontarget.setText("Sign in button pressed");
}
}
Clearle the #FXML annotation is doing the magic here. What's going on, and how do I make this work in Clojure?
Also, is there a way to bind the button press to the text change directly in the FXML so I don't really have to handle a gui->gui change in the code-behind, and instead only deal with the logic associated with the button press? I'm guessing yes, but I haven't gotten to that point in the tutorial.
thanks!
You need an explicit this argument in your handler:
(defn -handleSubmitButtonAction [this ^ActionEvent event]
...)
Perhaps a more accurate way of putting this is that event is the this argument in your handler as exhibited in the question text and you need to add a second argument to accept the event in and move the type hint to it (and probably rename the first argument to this for readability).
Given the fact that your code gets called at all, it would seem that JavaFX is happy to call a handler without passing it the event at all if it doesn't care about it (as evidenced by not having a formal parameter corresponding to it).
The type hint's only purpose is to allow the Clojure compiler to avoid emitting reflective code when ActionEvent methods are called on event. This will not prevent passing an object of a different type to the function.

jQueryUI .show() callback doesn't wait for animation to end

I must be missing something simple or I'm doing this completely wrong. My goal is simple. I want to animate .show() .hide() and I'm using callback to wait for one animation to finish and I get two problems.
animation is triggered twice
callback is executed to soon / doesn't wait for first animation to end,
Here's my jQuery code:
$('#miles').on({
keyup: function(){if($(this).hasClass('error')){$(this).removeClass('error',animSpeed);}},
focusin: function(){thisTime=$(this).val();if($(this).hasClass('error')){$(this).removeClass('error',animSpeed);}if($(this).val()=='miles'){$(this).val('');}},
focusout: function(){
if($(this).val()==''){$(this).val('miles');}
else if(thisTime!=$(this).val()){
if($(this).val().match(/^[0-9]+$/)&&$(this).val()>0){
$.post('include/process.php',{q:'saveMiles',e:$('#email').val(),w:$(this).val()},function(json){
if(json.error==null||json.error==undefined){
$('#saved').html('last saved '+json.date);
}else{
$(this).addClass('error',animSpeed);
if(json.type=='notaNumber'){$('#errorBox>p').hide('fade',animSpeedErr,function(){$('.'+json.type).show('fade',animSpeedErr);})};
}
},"json");
}else{
console.log('now');
$(this).addClass('error',animSpeed);
$('#errorBox>p').hide('fade',animSpeedErr,function(){console.log('now1');
if($('#miles').val()==0){console.log('now2');$('.notZero').show('fade',animSpeedErr);}
else{console.log('now3');$('.notaNumber').show('fade',animSpeedErr);}
});
}
}
}
});
var animSpeed=700;
var animSpeedErr=350;
json.type = what kind of error to show
#errorBox>p has display:none; declaired in CSS
Function of this code: check if #miles is a number and if number is greater than 0, if not, hide previous errors and show current one. If I run this script, I get this in console:
now
now1
now2
now1
now2
now1
now2
now1
now2
Script is live at http://developer.sodobniinternet.eu/concertdrive. Just enter a 0 or an letter into "miles" input box and you will see the problem.
I tried with:
.stop(true,true)
with no success.
Also tried to remove from callback and sometimes works like I want, sometimes not. That's why I think that there's a callback, to call a function when previous one finishes.
Thank you for any and all your help.
The problem lies in the selector:
$('#errorBox>p').hide('fade',animSpeedErr,function(){console.log('now1')
There are four paragraphs in the #errorBox and each is being hidden individually, so your .hide() callback gets called 4 times for each focusout event

Rails UJS: Preventing the event from propagating using 'ajax:before'

I am confused by how ajax:before works when using rails/jquery-ujs.
Does it wait for any given function in the ajax:before to complete before proceeding?
How do I completely cancel the event in jQuery if it fails some condition? (I do not seem to have a pointer to the event)
--
Update: I tried this, which normally works, but not now. =|
.bind('ajax:before', function(evt){
evt.stopImmediatePropagation();
} )
//also tried preventDefault, stopPropagation, etc
I answered my own question. "return false" in the ajax:before will cancel the action

Resources