How to display 0s for time using jquery mask plug in - jquery-ui

I am using Jquery mask plugin to display time.This mask does not allow to enter more than 2 as 1st number. But my requirement is if I enter '5', it should display as '05:00'.Could anyone please help me, how to achieve this.
Thanks in advance,

Can you try this block of code.
$(function() {
$('input).bind('keydown', function(e)
{
var keyCode = e.keyCode;
if (keyCode == ? ) //? check its more than 2
{
//read the value 5 and update the input with 05:00
}
});
});
I am not sure this is what exactly you want. But it will work

Related

jQuery Select2 & Validation Engine

How to correctly validate option value that uses Select2? I have a problem when some value is set before changing to any other. It looks correctly, but validation error is shown until I'll change value. Thank you for any help.
Try this solution.
How to make jQuery validation engine works well for select2()?
In select2.js file
Find this (Line 341)
if (this.indexOf("select2-") !== 0) {
And replace with
if (this.indexOf("select2-") !== 0 && this !== "validate[required]") {
I had the same problem. So in select2.min.js find this strokes (should be 2 strokes in script):
D(this.container,this.opts.element,this.opts.adaptContainerCssClass)
and add this code right after stroke you've found
,this.container.removeClass("validate[required]")
this should solve your problem.
add this css to your head tag.
.has-error {
border-color: #dd4b39 !important;
}
and this is how i am calling select2 for Jquery validation engine.
$("#form").validate( {
ignore: ".ignore, .select2-input",
rules: {
txtproduct: "required",
txtwarehouse: "required",
//txtdescription: "required",
txtquantity: {required:true,number:true},
txtrate: {required:true,number:true},
txtdiscounttype: "required",
txtdiscount: {required:true,number:true},
txtamount: {required:true,number:true},
},
highlight: function ( element, errorClass, validClass ) {
$(element).addClass("has-error");
if($(element).hasClass('select2-hidden-accessible'))
{
$(element).next().find("[role=combobox]").addClass('has-error');
}
},
unhighlight: function (element, errorClass, validClass) {
$(element).removeClass("has-error");
if($(element).hasClass('select2-hidden-accessible'))
{
$(element).next().find("[role=combobox]").removeClass('has-error');
}
}
} );
}
Select2 library make the original selector hidden, and validation engine can not work for hidden element, so first is make the visible, then the validation engine can see it. The second is we need to make the selector element hidden for us, there are about 2 ways to do, such as set it’s opacity into “0”, or make it’s height/width as “0px”, actually we need both.
Below is the code example:
$("select").select2();
$.each($(".select2-container"), function (i, n) {
$(n).next().show().fadeTo(0, 0).height("0px").css("left", "auto"); // make the original select visible for validation engine and hidden for us
$(n).prepend($(n).next());
$(n).delay(500).queue(function () {
$(this).removeClass("validate[required]"); //remove the class name from select2 container(div), so that validation engine dose not validate it
$(this).dequeue();
});
});
Reference: http://wangweiqiang.net/how-to-make-jquery-validation-engine-works-well-for-select2/

jQuery UI Selectable Without Selection Box

Given this example here: http://jqueryui.com/selectable/#display-grid I would like to make a selection without the "selection box" that appears when you click 'n drag. Namely, when I click on number 5 and drag to number 6 and then to 10 I get this:
where in fact what i would like to is drag from 5 to 6 to 10 and have only them selected without 9.
I searched the docs and couldn't find that option, and my google skills didn't bring me any luck, and I thought this must have been already done it's just so happens I can't grasp it on my own or find an existing solution, so any help here is appreciated (not saying you should do the research for me, am just hoping someone dealt with this before so he can point me to the right direction).
It also could be I'm missing the point in trying to accomplish this with jquery UI but this was the first such example I found that fits (kind of) what I want to accomplish.
First, you might want to hide .ui-selectable-helper or change the CSS:
.ui-selectable-helper{display:none;}
Next, do something like this:
$(function() {
var _mousedown = false;
$('#selectable').selectable({
start: function(event,ui){
_mousedown=true;
},
stop: function(event,ui){
_mousedown=false;
$('.ui-selected').removeClass('ui-selected');
$('.selecting').addClass('ui-selected');
},
selecting: function(event,ui){
if($('.ui-selecting').length == 1)
$(ui.selecting).addClass('selecting');
$('.ui-selecting').removeClass('ui-selecting');
$('.selecting').addClass('ui-selecting');
},
unselecting: function(event,ui){
if($(ui.unselecting).hasClass('selecting'))
$(ui.unselecting).removeClass('selecting');
}
});
$('#selectable').on('mouseenter', '.ui-selectee', function(){
if(_mousedown)
$(this).addClass('selecting');
});
});
DEMO:
http://jsfiddle.net/dirtyd77/7UVNS/5/ (HELPER HIDDEN)
http://jsfiddle.net/dirtyd77/7UVNS/6/ (HELPER VISIBLE)
Let me know if you have any questions!
***UPDATE:***
.selectable() is not able to do what you are looking for. However, here is something I created. Hope it helps!
JAVASCRIPT:
$(function() {
var _mousedown = false,
_last=null;
$('#selectable li').mousedown(function(){
_mousedown = true;
$('.ui-selected').removeClass('ui-selected');
$('#selectable li').attr('unselectable', 'on').css('user-select', 'none');
$(this).addClass('ui-selecting');
}).mouseup(function(){
_mousedown=false;
$('.ui-selecting').addClass('ui-selected').removeClass('ui-selecting');
$('#selectable li').removeAttr('unselectable style');
}).mouseenter(function(){
if(_mousedown){
if($(this).hasClass('ui-selecting'))
$(_last).removeClass('ui-selecting');
$(this).addClass('ui-selecting')
}
}).mouseleave(function(){
if(_mousedown){
_last = $(this)[0];
$(this).addClass('ui-selecting');
}
});
});
DEMO:
http://jsfiddle.net/dirtyd77/7UVNS/9/
***UPDATE #2:***
If you want to use this on a mobile device, I recommend changing up the format entirely to avoid any possible pitfalls. Here is how I would go about it:
JAVASCRIPT:
$(function() {
var _clicked = false;
$('#btn_select').click(function(){
_clicked = false;
$(this).hide();
$('#selectable li').removeAttr('unselectable style');
$('.ui-selecting').addClass('ui-selected').removeClass('ui-selecting');
});
$('#selectable li').click(function(){
if(!_clicked){
_clicked = true;
$('.ui-selected').removeClass('ui-selected');
$('#selectable li').attr('unselectable', 'on').css('user-select', 'none');
$('#btn_select').show();
}
if($(this).hasClass('ui-selecting')){
$(this).removeClass('ui-selecting');
}else{
$(this).addClass('ui-selecting');
}
});
});
*NOTE: you might want a $('body').click() to act as the end_selection button.
DEMO:
http://jsfiddle.net/dirtyd77/7UVNS/13/
This doesn't answer the original question, but it does show how to access the helper div of the selectable widget.
var helper = $( "#selectable" ).selectable('widget').data().uiSelectable.helper;
helper.css( { border:'none' } );

jQuery UI Range Slider event conditions

I need to use a Range Slider to set a time range (8-23) but I need some base conditions on it (I basically need the minimum range to be 1h):
When the two pickers are on the same position the right piker goes "+1"
On right limit (23) the values have to be "22,23)
Here is the code as I tested so far: JSFiddle URL
This works only before the right limit of the slider, when I have "23,23" or "22,23" my getSlide check function does not work properly and I don't understand how to fix it..
Any help?
Thanks!
I solved myself coding all conditions only in slide event:
...
slide: function (event, ui) {
val1 = ui.values[0];
val2 = ui.values[1];
if(val2-val1 < 1 || val1 > 22){
return false;
}
$("#start").text(ui.values[0]);
$("#stop").text(ui.values[1]);
},
...
The strange behaviour with the previous version is still not explained, but it works.

orientationchange event is not working

I am trying to detect the orientation change in the mobile devices,iphone and ipads.
I am using the below code:
$(window).bind("orientationchange", function (event) {
alert(event.orientation);
position = $.event.special.orientationchange.orientation();
event.preventDefault();
});
Here the value of alert i.e. event.orientation is displaying as "Undefined", where as i have read in some post that it does support for detecting the orientation.
Also in the jquery documentation it is written to better use "event.orientation" instead of "window.orientation" but none of these are returning the required result both are returning "undefined".
So i have used "$.event.special.orientationchange.orientation();" to detect the orientation.
But i want to use the functionality defined in the documentation of jquery as event.orientation. as in link
Also in my code "$.mobile.orientationChangeEnabled" is set to true, as given in the above link.
Please suggest me any possible solution for this.
Any help would be appreciated.
Thanks in advance.
Old question, but just in case anyone else comes across it, you have to use window.orientation, and that is expressed in degrees:
portrait: 0
portrait (upside down): 180
landscape: (counterclockwise): 90
landscape: (clockwise): -90
event.orientation isn't always set. I had this "undefined" problem in IOS safari. Instead, try using window.orientation:
//trigger a button click when orientation is changed to landscape mode
$(window).on('orientationchange', function(event) {
if (window.orientation == 90 || window.orientation == -90) {
$('.close-button').click();
}
});
window.orientation can be 0 or 180 (portrait mode), or 90 or -90 (landscape mode)
I had same issue. Just in case some one come across this question.
Try window.screen.orientation.type
jQuery( window ).on( "orientationchange", function( event ) {
if(window.screen.orientation.type == 'landscape-primary')
{
}
if(window.screen.orientation.type == 'portrait-primary')
{
}
});
Try this:
$(window).bind('orientationchange',function(){
if(event.orientation == 'portrait'){
alert('portrait');
}
else if(event.orientation == 'landscape') {
alert('landscape');
}
});
$(window).on("orientationchange", function (event) {

Jquery image slider without restriction of width

I have used the coin slider in my application.But the coin slider is restricted by the width.In my application ,I have split the document into two columns.The first column only contains coin slider.The second column contains the login panel.According to the width of the second column,the first column was adjust.I need to run my application in various screen size like 1280*768,800*600.is there any image slider in jquery without restrict width of image?Please help me. Thanks in advance.
jQuery(document).ready(function() {
id = '#coin-slider1'.replace(/:/g, "\\:");
var sliderWidth="";
jQuery(id).coinslider({width:sliderWidth,height:screen.height/4,delay:500});
})
Measure the width of the first column before using that value in the options array that you pass into the plugin...
jQuery(document).ready(function() {
id = '#coin-slider1'.replace(/:/g, "\\:");
var sliderWidth = $('#column1').width();
jQuery(id).coinslider({width:sliderWidth,height:screen.height/4,delay:500});
})
I have fix my problem with the help of calumbrodie.Thanks to calumbrodie.
I set the width of the tabPanel(parne to fo div of slider) as width of slider.
i got the width by the below code
document.getElementById('homeContentSubView:homeForm:tabPanel').offsetWidth
And my full code is,
jQuery(document).ready(function() {
id = '#coin-slider1'.replace(/:/g, "\\:");
var sliderWidth = ""; sliderWidth=document.getElementById('homeContentSubView:homeForm:tabPanel').offsetWidth-30; jQuery(id).coinslider({width:sliderWidth,height:screen.height/4,delay:750});
})
Thanks to all.

Resources