jQuery UI Slider - ajax result - jquery-ui

I am trying to implement a jQuery UI slider, where the slider value will be used to update a section of the page via ajax.
I can get the ajax to work, but I am having issues, getting the slider range to stay as the user has left it. Instead as soon as the slider handle is let go it pings back to default values.
Using jQuery 1.7.1, jQuery UI 1.8.16
Code:
$( "#example_slider" ).slider({
range: true,
step: 150,
min: 0,
max: 450,
values: [ 0, 450 ],
stop: function( event, ui ) {
var value1 = ui.values[0];
var value2 = ui.values[1];
$.ajax({
type: "POST",
url: "ajax_file.php",
data: "value1="+value1+"&value2="+value2,
cache: false,
success: function(html){
$("#content_update").html(html);
}
});
}
});

Ah my bad, Javascript initialization was also being called from ajax_file.php, which was why it was resetting the slider values. Removed this, and now works as expected.

Related

jquery dialog - push the background content down

I'm having a strange problem with the jquery dialog popup that I'm hoping someone here can help. The pop up codes looks like below. It works fine except for one thing. When the pop-up is displayed, it will sometimes push the background content down by about the height of the the dialog window. Is there a way to prevent this from happenning?
$("#searchPopUp").dialog({
modal: true,
bgiframe: false,
autoOpen: false,
resizable: true,
position:{ my: "center", at: "center", of: window },
title: 'Choose one search criteria and<br/>populate the corresponding field below:',
width: 400,
close: function( event, ui ) {},
buttons: {
"Search": function() {
$("#viewDevicesSearchForm\\:searchCommandLink").click();
},
"Close": function() {
$( this ).dialog( "close" );
}
}
});
This is because jquery sets position to relative, and then moves the popup to the right place using top and left. I found two ways to fix the problem:
1) The easier of the two: set margin-bottom of the dialog container to negative its height.
popup.dialog({
...other options...,
open : function() {
popup.css('margin-bottom', 0 - popup.height());
},
});
2) For the dialog container, set the position to absolute and adjust the top and left. To put it in the right place, add the offset position of where it is getting placed to the top value that jquery set. The calculation is similar for left.This should do it, but different parameters to the dialog may require different calculations.

Add ticks to Slider UI

I'm fairly javascript and jquery. I'm trying to add a slider to my webpage. It's a basic slider where anyone can select a value between 0-100. I'm not sure how to mark SOME intervals in the middle.
This is the code i have so far
<script>
$(function() {
var temp = 0;
$( "#slider" ).slider({
animate: true,
value:temp,
min: 0,
max: 100,
step: 1,
slide: function( event, ui ) {
$( "#amount" ).val(ui.value );
},
stop: function(event, ui) {
temp = ui.value;
//Do something
}
});
$( "#amount" ).val($( "#slider" ).slider( "value" ) );
});
</script>
It is functioning properly. What i wanna try to do is add interval markers at 0.25,50,75 and 100.
I have gone through a few questions on SO but not sure how to proceed with the implementation. Would appreciate the help.
I tried this implementation: http://jsbin.com/iwime but this is not what i am trying to do as i just want the ticks to appear at those regular intervals but users shold stll be able to select other values.
Thanks
Cheers
I am guessing you want something like this: http://jsbin.com/iwime/116
So, instead of using the number of ticks in the max option of slider, you use whatever max units you want to provide, e.g. 100. Then in refershTicks(), update the algorithm to toggle the class.
Slider settings:
var slider = $("#slider").slider({
...
max: 100, // the only change
...
});
And the refreshTicks() method:
function refreshTicks() {
var s = slider
, lo = s.slider("values", 0), hi = s.slider("values", 1);
var max = s.slider('option', 'max');
s.find(".tick").each(function(i) {
var i = (i + 1) * (max/ticks.length) - (max/ticks.length)/2; // the updated algorithm
var inRange = (i >= lo && i < hi);
$(this)
[(inRange ? 'add' : 'remove') + 'Class']("ui-widget-header")
[(inRange ? 'remove' : 'add') + 'Class']("ui-widget-content");
});
}
Similar to this SO Question : The answer from Bijan might help.
The implementation of jQuery UI slider he suggest may help you to find a solution:
http://www.filamentgroup.com/lab/update_jquery_ui_slider_from_a_select_element_now_with_aria_support/

JQuery UI: Change slider max inside of event handler

I am a little bit stuck:
I would like to change the "max" option of a JQueryUI slider while I am inside an event (e.g. change:).
How do I call the "max" option when I am inside an event?
EDIT: My code looks as follows:
$('#slider0').slider({
value: 100,
min: 0,
max: 500,
range: "min",
step: 50,
stop: function( event, ui ) {
var amt_val = (THIS IS THE CURRENT VALUE OF THE SLIDER)
if(amt_val === 400) {
$('#slider0').slider("option", "max", 10);
}
}
});
However, whenever I set the slider equal to 400, the handle and value go to 0, and the handle freezes.
You can change the option like
$( ".selector" ).slider( "option", "max", 7 );
Check the option tab of doc page for jQuery UI Slider
Demo: http://jsfiddle.net/joycse06/WKyYv/

Jquery auto complete

i want to style the autofill control scrollbar.
max and delay properties is not working in the jquery auto fill control.
i want to show alternate background colors in the menu item.
iam using jquery 1.4.4 and jquery-ui-1.8.7, jquery-ui-themes-1.8.7
do you have solution for this problem.
$('#zipcode').autocomplete({
minLength: 4,
max: 2,
delay: 10,
source: data.d,
focus: function (event, ui) {
$('#zipcode').val(ui.item.Zip);
return false;
},
select: function (event, ui) {
$('#zipcode').val(ui.item.Zip);
$('#state').val(ui.item.Abbreviation);
$('#city').val(ui.item.Name);
return false;
}
});
Here's how I implemented alternate background color:
$('#myautocomplete').autocomplete({
source: ...,
...
open: function (event, ui) {
$("li.ui-menu-item:odd").each(function () {
rdaJq(this).addClass("autocomplete-item-alternate");
});
}
});
Where "autocomplete-item-alternate" is a css class I defined in a stylesheet.
As far as I am aware, the jQuery UI Autocomplete plugin does not support a max option -
jQuery UI Autocomplete Documentation
Adding alternate background colors can be done by modifying the refresh method of ui.widget
var items = this.element.children("li:even:not(.ui-menu-item):has(a)")
.addClass("ui-menu-item even")
.attr("role", "menuitem");

jQuery UI Slider Change While Sliding

Edit: I still have not resolved this issue. If anyone has advice I would appreciate it.
I have a jquery slider with two bars that the user can change to select a price range. Below the slider I display min: $xxx and max: $xxx to show the current price range. Here's the code:
$("#slider-price .slider").slider({
step: 10,
animate: true,
range: true,
min: 0,
max: 500,
values: [range_price[0],range_price[1]],
slide: function() {
range_price = $(this).slider("option", "values");
$("#low-price-label").text("Min: $"+range_price[0]);
$("#high-price-label").text("Max: $"+range_price[1]);
}
});
The slide option looks at what the value of the slider is, and updates the min and max numbers. However, they only change on mouseup, after the user is done sliding the bar. I want the numbers to update as the user is sliding the bars. How do I do this?
I use this in a media player I wrote
slide: function(event, ui) {
$("#amount").text(ui.value);
}
edit: Just re-read your question, you should be able to use 'ui.values' instead of value to return the array , parse it and go from there.
edit2: Try this function instead of the one you have.
slide: function(event,ui) {
range_price = ui.values;
$("#low-price-label").text("Min: $"+range_price[0]);
$("#high-price-label").text("Max: $"+range_price[1]);
}

Resources