Is there any way to show month input type as number (i.e textbox with up and down arrow) instead of dropdown.
Please help on this. See my demo: https://jsfiddle.net/sharmilashree/VBGKU/1067/
.ui-datepicker-calendar tr {
text-align: center;
padding: 0;
background-color: #F6F6F6
}
This will be a difficult workaround. This is not easily done. Here is what I have so far:
https://jsfiddle.net/Twisty/ge6zh5es/6/
HTML
<p>Date:
<input type="text" id="datepicker" class="Highlighted" />
</p>
JavaScript
$(function() {
var minYear = 2006,
maxYear = new Date().getFullYear();
maxYear++;
var $dp = $("#datepicker").datepicker({
changeYear: true,
dateFormat: "dd-mm-yy",
yearRange: minYear + ':' + maxYear,
});
$dp.datepicker("setDate", "0");
function changeSpinner($dpObj) {
var $yearSpin = $("<input>");
$yearSpin.addClass("ui-datepicker-year");
$yearSpin.attr({
type: "number",
min: minYear,
max: maxYear,
value: new Date().getFullYear()
}).data("handler", "selectYear").data("event", "change");
$yearSpin.on("change", function() {
console.log("Spinner Change Event.");
var pDate = $dpObj.datepicker("getDate");
pDate.setFullYear(parseInt(this.value));
console.log("New Date: " + pDate);
$dpObj.datepicker("setDate", pDate);
});
console.info("Created Spinner: ", $yearSpin);
$dpObj.datepicker("widget").find(".ui-datepicker-year").replaceWith($yearSpin);
}
$("#datepicker").click(function() {
changeSpinner($dp);
}).change(function() {
changeSpinner($db);
});
});
This works the first time only. The datepicker itself does not have any events I can hook into to perform the replacement each time. I also have to add in some functions to get this new element to function properly with the datepicker.
I am considering removing the title bar items and separating them. I will update this answer with more details. Another option is to hide the select element and place a spinner over it. This spinner then changes the select element.
Related
I'm trying to disable years from my "YearPicker?", it's a DatePicker where you're only able to pick years. I need to disable all years and enable only a range of years (From 2012 to now, for example).
I'm using the JQueryUI DatePicker and it looks like this:
CSS:
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<style>
.ui-datepicker-calendar {
display: none;
}
</style>
JS:
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$('#datepicker').datepicker({
viewMode: 2,
format: 'yyyy',
maxDate: new Date(new Date().getFullYear(), 11, 31),
minDate: new Date(2012, 0, 1)
});
})
</script>
HTML:
<label>Year: <input class="form-control" type="text" id="datepicker"></label>
You can make what you're doing work, yet I think it's a bit more work than is needed. I would suggest maybe consider using Autocomplete instead. Take a look:
$(function() {
$("#datepicker").autocomplete({
minLength: 0,
source: function(req, resp) {
var today = new Date();
var min = today.getFullYear() - 6;
// Adjust above as needed, currently 6 years before this year
var results = [];
for (min; min <= today.getFullYear(); min++) {
results.push(min.toString());
}
resp(results)
}
}).focus(function(e) {
$(e.target).autocomplete("search", "");
});
})
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<label>Year: <input class="form-control" type="text" id="datepicker" data-years="6"></label>
Can move this to it's own function if needed too.
var function makeYearList(n){
var today = new Date();
var min = today.getFullYear() - n;
var results = [];
for (min; min <= today.getFullYear(); min++) {
results.push(min.toString());
}
return results;
}
You can also adjust the theming to list them horizontally versus vertically.
Hope that helps.
Solved! I was importing Bootstrap DatePicker and JQueryUI DatePicker, I thought that I was using the second one only, but the app was detecting only the first one, my code now is like this and working:
$('#datepicker').datepicker({
minViewMode: 2,
format: 'yyyy',
startDate: '2012',
endDate: 'y'
});
Thanks all for helping!
You could specify simple strings as well to achieve the desired formatting:
{
format: 'MM/yyyy',
startDate: '01/2022',
endDate: '12/2022',
}
I have a table and need to drag/drop cells containing data into blank cells. I'm able to drag and drop fine, but once a cell is dragged away, I need its "old" position to now become a droppable cell. Since the cell is dragged, I need something else to reference. I ended up wrapping each of the td elements in a div element, but all references return "undefined" on the inner cellDiv id (or return the outer tableDiv id). On the fiddle, I notice that the blue background is not appearing so I don't think the 'cellDiv' is doing much.
Next I am going to try swapping the td and cellDiv elements, but I decided to post the question first, as I've searched everywhere and cannot seem to find this specific problem addressed. Thanks for your help.
here is the problem in a jsfiddle: http://jsfiddle.net/tgsz34hx/3/
And the code:
<div id='tableDiv'>
<table>
<tr id='row1'>
<div class='cellDiv' id='r1c1'>
<td class='drop' id='col1'>Drop Here</td></div>
<div class='cellDiv' id='r1c2'>
<td class='nodrop' id='col2'>Drag Me</td></div>
</tr>
</table>
</div>
$(document).ready(function () {
var fromDiv;
$('.nodrop').draggable({
cursor: "move",
appendTo: "body",
revert: "invalid",
start: function (event, ui) {
var thisDiv = $(this).attr('id');
fromDiv = $(this).closest('.cellDiv').attr('id');
alert("thisDiv=" + thisDiv + ", fromDiv=" + fromDiv);
}
});
$('.drop').droppable({
accept: ".nodrop",
tolerance: "pointer",
snap: ".drop",
drop: function (event, ui) {
var parenttd = $(ui.draggable).closest('td').attr('id');
var parentdiv = $(ui.draggable).closest('.cellDiv').attr('id');
// alert("parenttd=" + parenttd + ", parentdiv=" + parentdiv);
$(this).removeClass('drop');
$(this).addClass('nodrop');
$(this).droppable('option', 'disabled', true);
}
});
});
#tableDiv {
background-color: grey;
}
#tableDiv td {
background-color: red;
}
#tableDiv div {
background-color: blue;
}
How the new jQueryUI's tooltip widget can be modified to open the tooltip on click event on certain element's on document, while the others are still showing their tootip on mouseover event. In click-open case the tooltip should be closed by clicking somewhere else on the document.
Is this possible at all?
Using jqueryui:
HTML:
<div id="tt" >Test</div>
JS:
$('#tt').on({
"click": function() {
$(this).tooltip({ items: "#tt", content: "Displaying on click"});
$(this).tooltip("open");
},
"mouseout": function() {
$(this).tooltip("disable");
}
});
You can check it using
http://jsfiddle.net/adamovic/A44EB/
Thanks Piradian for helping improve the code.
This code creates a tooltip that stays open until you click outside the tooltip. It works even after you dismiss the tooltip. It's an elaboration of Mladen Adamovic's answer.
Fiddle: http://jsfiddle.net/c6wa4un8/57/
Code:
var id = "#tt";
var $elem = $(id);
$elem.on("mouseenter", function (e) {
e.stopImmediatePropagation();
});
$elem.tooltip({ items: id, content: "Displaying on click"});
$elem.on("click", function (e) {
$elem.tooltip("open");
});
$elem.on("mouseleave", function (e) {
e.stopImmediatePropagation();
});
$(document).mouseup(function (e) {
var container = $(".ui-tooltip");
if (! container.is(e.target) &&
container.has(e.target).length === 0)
{
$elem.tooltip("close");
}
});
This answer is based on working with different classes. When the click event takes place on an element with class 'trigger' the class is changed to 'trigger on' and the mouseenter event is triggered in order to pass it on to jquery ui.
The Mouseout is cancelled in this example to make everything based on click events.
HTML
<p>
<input id="input_box1" />
<button id="trigger1" class="trigger" data-tooltip-id="1" title="bla bla 1">
?</button>
</p>
<p>
<input id="input_box2" />
<button id="trigger2" class="trigger" data-tooltip-id="2" title="bla bla 2">
?</button>
</p>
jQuery
$(document).ready(function(){
$(function () {
//show
$(document).on('click', '.trigger', function () {
$(this).addClass("on");
$(this).tooltip({
items: '.trigger.on',
position: {
my: "left+15 center",
at: "right center",
collision: "flip"
}
});
$(this).trigger('mouseenter');
});
//hide
$(document).on('click', '.trigger.on', function () {
$(this).tooltip('close');
$(this).removeClass("on")
});
//prevent mouseout and other related events from firing their handlers
$(".trigger").on('mouseout', function (e) {
e.stopImmediatePropagation();
});
})
})
http://jsfiddle.net/AK7pv/111/
I have been playing with this issue today, I figured I would share my results...
Using the example from jQueryUI tooltip, custom styling and custom content
I wanted to have a hybrid of these two. I wanted to be able to have a popover and not a tooltip, and the content needed to be custom HTML. So no hover state, but instead a click state.
My JS is like this:
$(function() {
$( document ).tooltip({
items: "input",
content: function() {
return $('.myPopover').html();
},
position: {
my: "center bottom-20",
at: "center top",
using: function( position, feedback ) {
$( this ).css( position );
$( "<div>" )
.addClass( "arrow" )
.addClass( feedback.vertical )
.addClass( feedback.horizontal )
.appendTo( this );
}
}
});
$('.fireTip').click(function () {
if(!$(this).hasClass('open')) {
$('#age').trigger('mouseover');
$(this).addClass('open');
} else {
$('#age').trigger('mouseout');
$(this).removeClass('open');
}
})
});
The first part is more or less a direct copy of the code example from UI site with the addition of items and content in the tooltip block.
My HTML:
<p>
<input class='hidden' id="age" />
Click me ya bastard
</p>
<div class="myPopover hidden">
<h3>Hi Sten this is the div</h3>
</div>
Bacially we trick the hover state when we click the anchor tag (fireTip class), the input tag that holds the tooltip has a mouseover state invoked, thus firing the tooltip and keeping it up as long as we wish... The CSS is on the fiddle...
Anyways, here is a fiddle to see the interaction a bit better:
http://jsfiddle.net/AK7pv/
This version ensures the tooltip stays visible long enough for user to move mouse over tooltip and stays visible until mouseout. Handy for allowing the user to select some text from tooltip.
$(document).on("click", ".tooltip", function() {
$(this).tooltip(
{
items: ".tooltip",
content: function(){
return $(this).data('description');
},
close: function( event, ui ) {
var me = this;
ui.tooltip.hover(
function () {
$(this).stop(true).fadeTo(400, 1);
},
function () {
$(this).fadeOut("400", function(){
$(this).remove();
});
}
);
ui.tooltip.on("remove", function(){
$(me).tooltip("destroy");
});
},
}
);
$(this).tooltip("open");
});
HTML
Test
Sample: http://jsfiddle.net/A44EB/123/
Update Mladen Adamovic answer has one drawback. It work only once. Then tooltip is disabled. To make it work each time the code should be supplement with enabling tool tip on click.
$('#tt').on({
"click": function() {
$(this).tooltip({ items: "#tt", content: "Displaying on click"});
$(this).tooltip("enable"); // this line added
$(this).tooltip("open");
},
"mouseout": function() {
$(this).tooltip("disable");
}
});
jsfiddle
http://jsfiddle.net/bh4ctmuj/225/
This may help.
<!-- HTML -->
Click me to see Tooltip
<!-- Jquery code-->
$('a').tooltip({
disabled: true,
close: function( event, ui ) { $(this).tooltip('disable'); }
});
$('a').on('click', function () {
$(this).tooltip('enable').tooltip('open');
});
I'm trying to 'popup' jquery autocomplete result under a textbox using the popover components of bootstrap.
I render results of the autocomplete query in an hidden div (#wrapper) and I want on render completion to set the content of my popover and show it.
For this I've overloaded the _renderItem function which append my results' divs inside the hidden container (#wrapper).
I thought the response function is called when _renderItem calls are done but I'm missing something as response function is never called.
Any solution?
Thanks!
$("#bookSearch")
.autocomplete({
minLength: 0,
source: '/Autocomplete/Books',
focus: function (event, ui) {
$("#bookSearch").val(ui.item.label);
return false;
},
search: function(event, ui) {
$('#wrapper').empty();
},
response: function (event, ui) {
$('#bookSearch').popover('destroy');
$('#bookSearch').popover({
html: true,
placement: 'bottom',
content: $('#wrapper').html()
});
$('#bookSearch').popover('show');
}
})
.data("autocomplete")._renderItem = function (ul, item) {
$('<div class="media"></div>')
.data("item.autocomplete", item)
.append("<a class=\"pull-left\" href=\"#\"><img class=\"media-object\" src=\""
+ item.ImgUrl
+ "\"></a><div class=\"media-body\"><h6 class=\"media-heading\">"
+ item.Name
+ "</h6>"
+ item.Author + "</div>").appendTo('#wrapper');
};
I fixed the problem by adding to my css file a z-index style for the autocomplete.
.ui-autocomplete {
z-index: 10000;
}
Remember to set a higher value for the z-index if it is necessary. Just for the record I have something like this in the HTML file
<div class="ui-widget">
<label for="employee">Employee:</label>
<input id="employee" type="text" name="employee" />
</div>
I have the following piece of Mootools 1.11 code (not upgradable as this is within Joomla), which I want to highlight the form row, when an item within it is focussed. However, this doesn't work. I need to know how to access the parent div of the form item.
window.addEvent('domready', function() {
var list = $$('#ChronoContact_lensorder div.formrow');
list.each(function(element) {
var fx = new Fx.Styles(element, {duration:200, wait:false});
element.addEvent('focus', function(){
fx.start({
'background-color': '#e6f0f2',
color: '#FFF'
});
});
element.addEvent('focus', function(){
fx.start({
'background-color': '#FFF',
'color': '#2F9AD0'
});
});
});
});
HTML is:
<div class="formrow">
<label for="ud">Uncut Diameter:</label>
<input type="text" id="ud" name="ud" />
</div>
Thanks
Instead of looking for the <div>s, you might want to look for the actual <input> using var list = $$('#ChronoContact_lensorder div.formrow input'); Then refer to the parent using the .getParent() method when necessary, like this:
window.addEvent('domready', function() {
var list = $$('#ChronoContact_lensorder div.formrow input');
list.each(function(element) {
var fx = new Fx.Styles(element.getParent(), {duration:200, wait:false});
element.addEvent('focus', function(){
fx.start({
'background-color': '#e6f0f2',
color: '#FFF'
});
});
element.addEvent('blur', function(){
fx.start({
'background-color': '#FFF',
'color': '#2F9AD0'
});
});
});
});
Untested code. Note that the second event is now blur instead of focus, or else both events will fire at the same time and might revert each other's effects!