Chosen:Trigger function if no results - javascript

I'm using Chosen jquery plugin. It shows "no results" if none found.
Is thera a way to trigger a function if no results found using this plugin?

Now, There is event chosen:no_results that you bind function to like this:
$('select.chosen-select').bind('chosen:no_results', chosenNoResults);
function chosenNoResults(evt, params) {
//Add new Option Logic
}
Refer Github for Reference

As a developer of Chosen I can safely tell you that there is currently no callback or event triggered when there are no results.
Although you could submit a feature request as an issue at the GitHub repository
The last few weeks there has been active development on Chosen, so changes of quick action upon your request are good.

Related

Listening on Apache Tapestry form events

I'm a Back-end dev, and recently inherited a couple of legacy Apache Tapestry systems. My skills with Tapestry are null my knowledge on javascript medium.
I want to disable a submit button right before the submit is made to avoid multiple submits.
A very simple
$(document).ready(function () {
$("#form").submit(function () {
$("#submitbutton").attr("disabled", true);
return true;
});
});
approach wont do because the submit event is propagated before Tapestry does the client-side validation, so I could be disabling the button on a submint attempt that will fail validation.
On this question I learned that Tapestry also propagetes its own events, and if I could listen on tapestry:formprocesssubmit That would probably solve my problem.
I have my CreateContract.tml file with the form, fields and buttons that already work, I have my CreateContract.java file with
#Import(library = {
"context:js/jquery.mask.min.js",
"context:js/maintain-contracts.js",
"context:js/zone-overlay.js"},
stylesheet = "context:layout/zone-overlay.css")
And my maintain-contracts.js file with
$(document).ready(function () {
$("#form").on('tapestry:formprepareforsubmit', function () {
console.log("I want to arrive here!");
});
});
But it doesn't work.
On this mailing list thread I see people discussing very similar matters, but they go about listening on events on a different fashion, that I don't quite grasp.
Should I create the listener inside the initializer?
I'm reffering to the event as 'tapestry:formprepareforsubmit' instead of Tapestry.FORM_PREPARE_FOR_SUBMIT_EVENT because on both my maintain-contracts.js and my console the Tapestry variable is empty - why is that?
What about the .on versus .bind versus .observe trichotomy?
the first links's question was solved using ProptypeJS Class.create, but I think i dont have access to that.
I'm I going about that wrong?
Thank you, any help is appreciated.
Not an analysis of why your approach doesn't work, but a useful referral nonetheless:
Geoff Callender, creator of Tapestry JumpStart, has an excellent description of how duplicate form submissions can be avoided using a mixin.
See http://jumpstart.doublenegative.com.au/jumpstart/examples/javascript/creatingmixins1
After reading Tapestry's source code, i found out that the event is not called tapestry:formprepareforsubmit, but t5:form:prepare-for-submit, even though I found no documentation of that anywhere.
So
$(document).ready(function () {
$("#form").on('t5:form:prepare-for-submit', function () {
console.log("I want to arrive here!");
});
});
Works perfectly.

Framework7 - PhotoBrowser onClose function

I am using framework7in my mobile app and I want to PhotoBrowser to display my images.
However, I want to detect when user close the PhotoBrowser so that I can process whatever is needed. In the documentation there is a onClose(photobrowser) callback function. But I am not sure how it works.
Based on the developer's coding conventions, it should be:
myPhotoBrowser.on('close', dosomefucntion());
but error:
myPhotoBrowserPopupDark.on is not a function
I tried
onClose(myPhotoBrowser, dosomefucntion());
and nothing happen, not even error.
I check his other framework SwiperSlider, he seems to use
mySwiper.on('slideChangeStart', function () {
console.log('slide change start 2');
});
to handle the callback function.
What seems to be the issue and how can I resolve this?
what is type property of your photoBrowser? if you set your photoBrowser object type to "page" onClose event won't trigger.
https://github.com/nolimits4web/Framework7/issues/1243

Checking to see if a plugin has been initialized in jQuery?

I'm using the select2 jQuery plugin (V4) and from what I can see they don't have an onInitialized event; but I need to run some code after it has been initialized.
By Initialized I mean that it has completed and that all elements associated to it are now ready.
I seen this question, but none of the answers seem to address the issue of continually checking until it becomes available; like what if it's not there the first time you check, then the code you needed to run wouldn't run.
I thought of using setInterval with something like the above but wasn't sure if there was a better way?
The only way you can go async it's when you fetching remote data, so you can inject you callback in that ajax.
If you have several ajax calls use deferred:
var deffered1 = $.Deferred();
In your ajax calls after success and error use the following code to resolve those calls.
complete:function(){
deffered1.resolve()
}
And to subscribe for events:
$.when(deffered1, deffered2).done(function() {
// your initialized actions
})
If you have more than 1 select elements on your page which needs to be converted to select2 dropdown then you can use the following: Multi Select version
if you have just a single select on the page, you can go with the following:
Single Select option:
Hope it helps.

how to restore back data in template using knockout.js

I want to build a template like gridview. My problem is when I edit the data '123qwe' to '123' but when i click 'cancel' button not to edit the data. the data not restore back to '123qwe'.
I have a workaround to solve this, however, it is not work in my computer but in jsfiddle, I want to know the reason and help to solve in a knockout.js format. Thank you~~~
code to attention:
// Reset button
self.reset = function (index) {
self.nameLists([]);
$.each(og_arr, function(i,item){
self.nameLists.push(new nameFilter(item.name));
});
this.editTemplate("readOnlyTemplate");
};
program in jsfiddle
There is no built-in notion of canceling an edit. You are editing an observable. Have a look at protected observables, a simple extension that allows you to commit or reset a change.
For general "undo" functionality, check out the Memento plugin for Knockout.
(I didn't write it, just a satisfied user)

Dojo Calendar Not Destroying On My Connect

Hey all, this is weird. This widget will not destroy onHide. I know the event is firing because I have placed debug code within the function that is ran. I have no idea why this won't work... it is clearly documented in the API. My code is below:
var formitem=new dijit.Calendar({
name:this.formitems.calendaritems[i].id,
id: this.formitems.calendaritems[i].id
},
dojo.create('dd',null,
this.lineitems));
dojo.connect(myself.dialog, 'onHide', function() {
formitem.destroy();
});
I keep getting the error the widget is already registered, however if the destroy function is supposed to work correctly then it is supposed to destroy the instance of it. Please help.
"the widget is already registered" error results from using a ID that's already been used. If you have to set the id, ensure that you never use the same one twice. But I would just remove that line where you set the id. Somewhere along the line you are recreating the Calendar. It's possible that you are deleting it as expected but its trying to recreate.
Note this is a bit of guess, since the example seems to be missing code that is relevant to your problem.

Categories