In JQuery multiselect. http://www.erichynds.com/blog/jquery-ui-multiselect-widget
Can we selectively disable some of the unchecked options in the select-box upon selecting(checking the checkbox) one option.And enabling them again upon deselecting the one.
Thanks
You can apply this class to the options which you want to be disabled. class="ui-multiselect-disabled " and vice versa.
I hope you know the logic to do so :)
EDIT:
$("select").change(function () {
var str = "";
var op=$("select option:selected");
op.addClass('newclass');
str = op.text() ;
//op.css('background-color', 'red');
alert("selected"+op.attr('class'));
$("select option").each(function () {
var temp=$(this).text() ;
if(str!=temp){
$(this).removeClass('newclass');
alert(temp);
}
});
});
Happy coding :)
Related
I'm trying to use select2 jQuery plugin to enhance a select element in HTML app. The select allow to choose multiple items.
I'll like to remove the items that are currently selected from the dropdown. I didn't find explicit solution in the docs.
The current solution I've found was to use templateResult option and have the template function return null if the item is selected. This cause Results.prototype.template function to set container.style.display = 'none' but this has the side-effect of causing the keyboard to still select those items even though they are not visible.
Just apply this CSS.
.select2-results__option[aria-selected=true] { display: none;}
Small Update for recent versions :
.select2-results__option--selected { display: none;}
Source
Check out the answer provided here, provided by Hakam Fostok.
I've reproduced his answer below here for completeness:
my solution was modified the select2.js (the core, version 4.0.3) in the line #3158. Add the following verification :
if ($option[0].selected == true) {
return;
}
With this verification, we can exclude from the dropdown list, the selected ones. And if you write the name of a selected option, appear the text of option "noResult" .
Here the complete code:
SelectAdapter.prototype.query = function (params, callback) {
var data = [];
var self = this;`
var $options = this.$element.children();`
$options.each(function () {
var $option = $(this);
if (!$option.is('option') && !$option.is('optgroup') ) {
return;
}
if ($option[0].selected == true) {
return;
}
var option = self.item($option);
var matches = self.matches(params, option);
if (matches !== null) {
data.push(matches);
}
});
callback({
results: data
});
};
For my purposes, I was using the select2.js file, so I made the change at line 3195.
For versions 4 and 4.1
.select2-container--default .select2-results__option[aria-selected=true] {
display: none !important;
}
Works fine!
In addition to #Satheez answer, this script will let you maintain the placeholder after hiding all the selected items.
$('.selector').select2().on("change", function (e) {
$('.select2-search__field').attr('placeholder', 'Here is your placeholder');
});
Does Dart have childSelector in event function like jQuery on()? Because I want fire contextmenu event only if mouse hover specific element type.
This is my javascript code.
var $contextMenu = $("#context-menu");
$("body").on("contextmenu", "table tr", function(e) {
$contextMenu.css({
display: "block",
left: e.pageX,
top: e.pageY });
return false;
});
But I don't know how to check if hover "table tr" in my Dart code.
var body = querySelector('body');
var contextMenu =querySelector('#context-menu');
// fire in everywhere
body.onContextMenu.listen((e) {
e.preventDefault();
contextMenu.style.display = 'block';
contextMenu.style.left = "${e.page.x}px";
contextMenu.style.top = "${e.page.y}px";
}
You can filter events :
body.onContextMenu.where((e) => e.target.matchesWithAncestors("table tr"))
.listen((e) {
e.preventDefault();
contextMenu.style.display = 'block';
contextMenu.style.left = "${e.page.x}px";
contextMenu.style.top = "${e.page.y}px";
});
the problem is the following:
$("body") gives you a set of elements that does not change. The `.on(..., 'sub selector') however is actually bad, because it checks the subselector against the target of the event EVERY TIME for every event.
I see two solutions here:
The first is to select all children and add the event listener to all of the elements:
var body = querySelector('body');
body.querySelectorAll('table tr')... onContextMenu...
But this will not work if you insert tr into the table later.
The other way is to check the .target of your event and see if it's a tr and if its in your table. I hope this already helps. If you need more detailed help let me know!
Regards
Robert
I use stackoverflow often so thanks to all who contribute - its been very helpful.
I am not an avid programmer and use jquery at its most basic level. I hope someone can help.
I would like to dynamically change the href url of '.nexttab' controls so that the user can move onto the next html page.
The below is my (juvenile) code.
$(function() {
$("#tabs").tabs();
$(".nexttab").click(function() {
var selected = $("#tabs").tabs("option", "selected");
$("#tabs").tabs("option", "selected", selected + 1);
var href = $(this).attr('href');
var lasttab = $(this).ui.panel('id');
if(lasttab == 'tabs-7'){
$('.nexttab').attr('href', href.replace('#','http://google.com.au'));
}
});
$(".prevtab").click(function() {
var selected = $("#tabs").tabs("option", "selected");
$("#tabs").tabs("option", "selected", selected - 1);
});
});
html is here
<div id="control-arrows">
< Back | Continue >
</div>
How can I identify the correct panel or tab (which is always the last) and then make the url change ?
Thank you,
Sarah
Having an issue similar to '“Select All” does not work with twitter bootrap modal and IE', answered by merv. (thanks much merv)
Fiddle of the issue: http://jsfiddle.net/lesouthern/5ked9/
In simple call of datepicker:
$('input').datepicker();
Before using datepicker, Ctrl-A works.
After Ctrl-A and Select all are disabled with IE (confirmed with IE8).
Do I turn off an event for datepicker, as done with modal? Tried many combinations of this with no luck.
Thank you
This may be less of a solution, and more like a hack.. but hey, I'm working with IE8..
Here is the angularjs directive I wrote that solved the problem.
My datepickers are in modal dialogs, and on view of them datepicker is intialized, and when they close, datepicker gets destroyed, and the div it creates removed. This is the only way I have been able to restore ctrl-a in this environment.
Before datepicker is intialized, and after it's destroyed, Ctrl-A works in IE8. That's good enough for me.
<input class="span2 paused-until"
datepicker-wrapper="{
maxDate : getMaxDate()
}"
ng-change="error=false"
ng-model="pausedUntil"
name="Paused Until"
size="16"
type="text"
ui-validate='{validFutureDate : validateDate}'
ng-pattern="/^(\d{1,2})-(\d{1,2})-(\d{4})$/"
required />
.directive('datepickerWrapper',function() {
return {
restrict : 'A',
link : function($scope,$element,$attrs) {
$scope.$watch('modal.model',function(m) {
var _attrs = $scope.$eval($attrs.datepickerWrapper);
var maxDate = (typeof _attrs === 'undefined' ||
typeof _attrs.maxDate === 'undefined') ?
null : _attrs.maxDate;
//if the dialog is open, create the datepicker
if(m) {
$element.datepicker({
minDate : '+1d',
dateFormat : 'mm-dd-yy',
showOn : 'button',
buttonText : '<i class="icon-calendar"></i>',
maxDate : maxDate,
onSelect : function(dateText) {
//assign the selection of the
//text to the element's model
$scope[$attrs.ngModel] = dateText;
$scope.$apply();
}
});
}
//else completely remove this element and generated div
else {
$element.datepicker('destroy');
$('#ui-datepicker-div').remove();
}
});
}
}
})
I am attempting to insert a textarea into a JQuery dialog and I am getting hung up on the syntax of how the dialog I have to work with is set up (I didn't write the dialog by the way, I just want to make changes to it). I have looked at some of the other questions that are similar to this on this site but they don't seem to answer my question so I am hoping someone can shed some light on this for me.
Here is the code:
$('.rejection_toggle').button().click(function(event) {
var $dialog = $('<div />', {
text: Drupal.t('Are you sure you want to reject this form? If so, then please leave a comment as to why you are rejecting it.')
})
var $button = $(this);
$('body').append($dialog);
$dialog.dialog({
title: Drupal.t('Reject this form?'),
buttons: {
'Reject': function (event) {
var $submitID = $button.attr('id').replace('rejection-toggle', 'approval-buttons-reject'),
$submitButton = $('#' + $submitID);
$submitButton.click();
$dialog.dialog('close');
},
'Cancel': function (event) {
$dialog.dialog('close');
}
}
});
return false;
});
So how would I go about inserting a textarea before the buttons?
Thanks.
Ok I figured it out. I need to add:
var textArea = $('<textarea style="width:100%" />');
$dialog.append(textArea);
After the var $dialog line.
Now I need to figure out how to get the input back into Drupal.