Select2 add class to select2-container when no results - jquery-select2

I would like to be able to add class to the select2-container div when their is no results. Is this possible because there doesn't seem to have any way to catch an even when there is no results.
Thanks!

I would add the class first and then remove it on the change event.
$('.nameOfContainer').on('select2:change', function (evt) {
$(this).removeClass('noResults');
});

Related

How can i make DatePickerFor a readonly?

i have the DatePickerFor and i want to make it readonly I want to force user to pick dates ,not being able to type them.
<td>#(Html.Kendo().DatePickerFor(model => model.DateRecherche).Max(DateTime.Today))</td>
Thanks.
Is it in their docs:
//DISABLE inputs
$("#datepicker").attr("readonly", true);
$("#monthpicker").attr("readonly", true);
So you will need a little bit of javascript along with your view code to implement this behavior
Adding the attribute readonly to an input tag will make it read only. You can do this with jQuery like this:
$(function () {
$('.k-datepicker input').attr('readonly', 'true');
});

Umbraco custom Data Type - how to hide label?

I am creating a custom Data Type for Umbraco.
It is a UserControl (.ascx file) derived from IUsercontrolDataEditor.
(It shows a grid that lists all the child nodes)
How do I make this control full-width?
ie. I want to hide the label, just like what you can do with RichTextEditor by unchecking 'Show Label'.
EDIT: Thanks for the answers :) Another way to do this is using AbstractDataEditor, but it is more complicated.
For Umbraco 7.x using an angularJs-controller for your custom datatype just change the property hideLabel of the inherited model on the scope:
$scope.model.hideLabel = true;
The only way I know of is to use some javascript as in this forum post.
This is a bit of a workaround but should be OK for an admin function (where Name is the label you want to suppress):
<script type="text/javascript">
jQuery(document).ready(function () {
$("div.propertyItemheader:contains('Name')").hide();
});
</script>

jQuery Sortable: helper option

I have 2 sortable lists, let's say "modules" and "available-modules"
$(".available-modules").sortable({
// helper: 'clone'
// or
helper: function(e, elt) {
return elt.clone(true);
}
})
None of this work: when I drop an item from "available-modules" to "modules", the item from "available-modules" is removed. I thought that using helper: clone would just insert the clone, not the actual item.
Is this my responsability to reinsert the element in the "available-modules" list after inserting it in the other one or is there a problem with my helper option?
Thanks.
It seems like you need something a bit like this demo:
http://jqueryui.com/demos/draggable/#sortable
The drag "source" isn't sortable, just draggable, and makes use of the connectToSortable option.

Rails - Access AJAX Triggering Element in Callback

I have a view, say show.js.erb. And I have a link in another view such that
link_to "MyLink", my_object_path, :remote => true
successfully returns the show.js.erb view. My question is, from within that view, is there any way to access the element that triggered the AJAX call without having to resort to generating an id specific to individual elements a la ...
I want to be able to use this view callback to open a small dialog next to whatever element was clicked on, but I can't seem to find a way to access the triggering element.
I tried using $(this) but that doesn't work.
I'd like to do something along the lines of
$(this).after("some new html here");
My solution was to bind a pre-submit class to the element, in my case a popup modal window. It's a similar solution to the post linked to above in that it uses the pre-submit bindings, but tailored to use classes instead.
In public/javascripts/application.rb:
jQuery(function($) {
$(".poppable").bind("ajax:loading", function() { $(this).addClass("popped"); });
});
Then in my view for the popup content (e.g. app/views/mymodel/popup.js.erb):
var p = $(".poppable.popped");
p.removeClass("popped");
/* Do what I need to with p ... */
If this doesn't look kosher, I'm all ears but it works for now.

Javascript to disable button residing inside a user control

I am using a "user control" which contains a button and other controls. I am using it in an aspx page. I want to diable the button using Javascript. By any chance, is it possible to achieve this?
Thanks
Lijo
I don't really get what you mean by 'disable', but to take it away you get the element in Javascript in an object and use:
element.style.display = "none";
That completely takes it away, to just make it invisible use:
element.style.visiblity = "hidden";
To get the element in an object, the easy way is once you know the value of the id attribute, say it's id="bla", you use
element = document.getElementById("bla");
You can also just use:
document.getElementById("bla").style.display = "none"; // etc
Of course, CSS is far simpler, use:
#bla {display:none;} /* etc, can also be with visiblity */
But I'm not really sure what you mean with 'disable', also, disabling with JavaScript is NOT a form of good security, JavaScript can be turned off, also, the source can be inspected to just work around it.
Edit: Some clarification: display:none; just treats it as if it isn't there at all. visiblity:hidden; makes it completely transparent, but other elements around it are still placed as if it were there.
Don't remove or hide the element as the other answers suggest. Form elements in HTML have a disabled attribute for a reason. With Javascript you would select the button element (however you are selecting elements) and set the disabled property like this:
buttonElement.disabled = true;
To reenable the button:
buttonElement.disabled = false;
Obligatory jQuery:
$(buttonSelector).attr('disabled', true); // Disable
$(buttonSelector).attr('disabled', false); // Enable
If you mean to set the attribute "disabled" it is possible
$(element).attr("disabled", "disabled"); // jQuery
element.setAttribute("disabled", "disabled"); // js
If you really need to remove literally you can use jQuery Remove
$(element).remove();
or do it by hand
var el = document.getElementById(id);
el.parentNode.removeChild(el);
if just hide is enough, I recommend doing this with CSS

Resources