I'm trying to create a custom Picker whose data is from a remote JSON. The problem is that it doesn't fire the 'change' event on the picker at the first time when I select a row from the picker, I have to close the picker and select a row from the picker again and then the event change works.
var clubs_data = [];
//custom object to handle the httpClient
new K().scoutmobile.Tools.getData(new K().scoutmobile.URL_BASE, {Accion:new K().scoutmobile.CLUBS}, function(_response){
if(response.status.codigo === "RESULT"){
clubs_data.push(Ti.UI.createPickerRow({title:'select a club'}));
for(_j in _response.data){
clubs_data.push(Ti.UI.createPickerRow({color:'#fff',title: _response.data[_j].Propiedades.club_nombre.Valor, id:_response.data[_j].Propiedades.club_id.Valor}));
inputClubs.add(clubs_data); //where inputClubs is created previously
}else{
new K().scoutmobile.Tools.createDialog('invalid_user_alert_dialog_title','invalid_user_alert_dialog_message');
}
});
//event listener
inputClubs.addEventListener('change', function(e){
Ti.API.info(e.row.id);
});
win.add(inputClubs);
In the Titanium Studio Console I get this:
[WARN][InputManagerService( 60)] Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#43f8dbb8
Any ideas what it is happening?
I have three solutions for this, none of them are good enough:
A very stupid solution would be having picker pointing at empty option at start, then user need to change it anyways
If you loading another element of UI using that picker value, you can preload that part with the default (or first) option
You can modify Titanium SDK source code, where they write this log "Window already focused' and fire change event instead. This is pretty simple, I have done that for TabGroup control, it may take 2 hours of your time (either for Android or iOS)
Related
I am using PowerBuilder 2017 and have created an OLE control (Microsoft Web Browser) with a local html file using Leaflet JS.
When a user clicks on a marker on the leaflet map I would like a reference value (coordinates) sent back to PowerBuilder where the code there can react to the user event.
My question is how can I get a javascript event to also trigger an event in the main PowerBuilder application?
After a lot of investigating I have managed to solve my problem, I added the following code into PowerBuilder, inside the OLE Control's click event:
oleobject lole_data
string ls_innertext, ls_classname
lole_data = This.Object.Document.ActiveElement
if not IsNull(lole_data) then
ls_classname = Lower( string(This.Object.Document.ActiveElement.classname))
if ls_classname = "leaflet-popup-content" then
ls_innertext = string(lole_data.parentNode.InnerText)
end if
end if
ActiveElement is the method to use. I obtain the Leaflet class and can identify it is in fact a Marker PopUp that was clicked.
I'm using the bootstrap-datepicker from eternicode and I'm against a strange behaviour.
When I try to use the setDatesDisabled option on the fly with the default startDate and endDate option, the datepicker seem to freez and don't allow me to change the month any-more.
The strangest thing is a simple alert() just before the call of setDatesDisabled seem to correct the bug...
My final need is to add some disabledDate on the fly, using a function as a data provider
The simplified code :
// enable the datepicker on fields
$('.date-picker').datepicker({
format: 'yyyy-mm-dd',
startDate: '2016-04-01',
endDate: '2016-08-15',
datesDisabled: ['2016-04-21','2016-04-20','2016-04-13']
})
.on('show', function(ev){
// #TODO check why bug here...
// alert('hi'); // uncomment to patch bug
$(this).datepicker('setDatesDisabled', ['2016-04-17','2016-04-16']);
});
Check the JSFiddle to reproduce.
Does anyone face the same thing / have a work around to disable some date on the fly ?
I've already make a bug report on the eternicode Github, as I think is may be an internal bug.
Its most likely due to the fact that the datepicker 'show' event fires multiple times as you navigate while the datepicker calendar is open.
Setting disabled dates while the callendar is already opened causes it to be recalculated and reloaded so it navigates back to the month with the currently selected date - this makes it impossible to navigate away from the page with the selected date (the half working scenario happens when there is no selected date).
Not sure if this is applicable in your scenario but this should work when you set the disabled dates only when calendar is not opened.
I changed
.on('show', function(ev){
to
$('.date-picker').on('click', function(ev){
and this seemed to work fine, see the updated fiddle:
https://jsfiddle.net/zj9sjspf/11/
Second slightly "hackish" solution is that you could disable automatic showOnFocus, and manually check if the calendar is not opened + set the new disabled dates + trigger show manually when the field is being focused on. This is not the best way of doing this, but might be the way to go while you wait on replies on your bug report ;)
One way of doing this can be seen here:
https://jsfiddle.net/zj9sjspf/13/
I faced the same issue with setEndDate and setStartDate on the fly. The datepicker was broken and couldn't change month, year etc and solved it like this:
var setDatesDisabled = false;
$('.datepicker').datepicker({
// Whatever options
})
.on('show', function(e) {
if (!setDatesDisabled) {
$(this).datepicker('setDatesDisabled', ['2016-04-17','2016-04-16']);
setDatesDisabled = true;
}
})
.on('hide', function(e) {
setDatesDisabled = false;
});
The show event will only run when the datepicker opens and NOT as you navigate.
Is there a way to restore the original content / undo all changes of an element that had become an Inline-CKEditor?
There does not seem to exist a build-in function for that, see for example this ticket.
Some propose workarounds like a button with onclick javascript event, which reloads a page. Or saving the initial data inside of the editor and use javascript to replace the content with that on an event again. (Here is a thread concerning your request with the mentioned tricks.)
My solution:
After instantiating CKEditor I save the initial content with CKEDITOR.editor1.getData() to a custom variable CKEDITOR.editor1.firstSnapshot. Later when I want to restore it I write it back with CKEDITOR.editor1.setData(CKEDITOR.editor1.firstSnapshot);
At first I wanted to use getSnapshot() but however it always returned true, so that didn't work for me.
I want to share a different approach to problem. I'm using inline CKEditor, and have on blur event (when user unfocus ckeditor) which prompt option for saving content or rollback changes.
For case of rollback - i just put checkDirty() - function which check if instance has changes - in while loop, so undo executes in each true until ckeditor will be restored to initial state.
Code will look like this:
CKEDITOR.instances["editor"].on('blur', function (evt) {
if (confirm("Do you wish to roll back changes ?")) {
while (CKEDITOR.instances["editor"].checkDirty()) {
CKEDITOR.instances["editor"].execCommand('undo');
}
} else {
// do nothing!
}
})
http://jsfiddle.net/5Ha9d/
I am using zeroclipboard plugin to add the text on click the submit button. Everything seems working but i want it to be automated for certain condition. I am not sure which is the correct way of triggering click event. I already tried with default as $('#copy').click();
I know it is in flash but i tried to know whether it is working or not but as long i unable to do this.
Here is the code i tried
//set path
ZeroClipboard.setMoviePath('http://davidwalsh.name/dw-content/ZeroClipboard.swf');
//create client
var clip = new ZeroClipboard.Client();
//event
clip.addEventListener('load', function () {
clip.setText(document.getElementById('box-content').value);
});
clip.addEventListener('complete', function (client, text) {
alert('copied: ' + text);
});
//glue it to the button
clip.glue('copy');
jQuery('#copy').click();
Is there is a way to trigger this submit button on page load. Not sure is something straight forward.
Thanks for your suggestion.
Vicky
According to this thread, you can't simulate a click on the flash object, and have it setData in the clipboard http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/desktop/Clipboard.html#. It's a security precaution by Adobe.
I'm using RadScheduler for my project. In the scheduler, I need a periodical update, so in my javascript, I set interval for a method that call rebind() on the RadScheduler for every 60 seconds. The problem is that, when my user open the advanced form, the rebind() method makes the form disappear. How can I detect AdvancedForm opening and closing event so that I can stop /restart the timer ?
Thank you in advance.
While there is an event for when the RadScheduler opens its Edit form, called OnClientFormCreated, there is not one for when the edit form closes. There are ways to do this though, but you have do add some additional code.
When you think about it there are several different items that can lead to the form closing - the user can click on the close icon at the top right (or left, depending on your orientation) of the window, they can click cancel, or they can hit save.
Keeping that in mind, we can take a look at this demo, which shows the Advanced Edit Form in action, and also has some JavaScript pre-written for us.
Within the schedulerFormCreated() function we can do the following:
function schedulerFormCreated(scheduler, eventArgs) {
// Create a client-side object only for the advanced templates
var mode = eventArgs.get_mode();
if (mode == Telerik.Web.UI.SchedulerFormMode.AdvancedInsert ||
mode == Telerik.Web.UI.SchedulerFormMode.AdvancedEdit) {
// Initialize the client-side object for the advanced form
var formElement = eventArgs.get_formElement();
var cancelButton = $("[id$='_CancelButton']");
cancelButton.on("click", formClosed);
var templateKey = scheduler.get_id() + "_" + mode;
....
And then we have the formClosed event:
function formClosed(eventArgs) {
}
in formClosed you can just create your logic for resuming the timer, while in schedulerFormCreated you can directly call the function that stops the timer right after that if-statement.
In case you're wondering what we're doing here we're simply grabbing an instance of the jQuery object representing the element with an id that ends with _CancelButton (we're not interested in the beginning part) and then just binding to the click event using the .on() jQuery function.
To get an instance of the save button you just have to use _UpdateButton, and for the close icon it is _AdvancedEditCloseButton. Keep in mind that any element that ends with these substrings will be selected, so if you want to be more specific I recommend inspecting the elements of your advanced form using FireBug or the Chrome Dev tools to get their ID and plug that into the selector above.
This should allow you to get the functionality you're looking for.