First time here, and more of a web designer than programmer, so be gentle! ;o) Anyway, as the title suggests, I have a dialog window that's opened and within that, a datepicker. What I want it that, if the user opens the datepicker, and then clicks the dialog window's close button, the datepicker is also closed.
Here's what I've got at present:
<!--// Modal Windows -->
$.ui.dialog.defaults.bgiframe = true;
$(function() {
$('#advanced_search').dialog({
autoOpen: false,
width: 600,
height: 400,
modal: true,
resizable: false,
draggable: false,
title: 'Advanced Search',
});
$('.adv_search').click(function() {
$('#advanced_search').dialog('open');
});
});
<!--// Date Picker -->
$("#advanced_search .start_date").datepicker({
dateFormat: 'dd/mm/yy',
showButtonPanel: true,
duration: 0,
constrainInput: true,
showOn: 'button',
buttonImage: '/img/icons/50.png',
buttonImageOnly: true
});
$("#advanced_search .end_date").datepicker({
dateFormat: 'dd/mm/yy',
showButtonPanel: true,
duration: 0,
constrainInput: true,
showOn: 'button',
buttonImage: '/img/icons/50.png',
buttonImageOnly: true
});
But I'm a bit flummoxed as to how to do this. Anyone got any advice? It'd be much appreciated!
Thanks
Phil
Add the close callback to your dialog like this:
$(function() {
$('#advanced_search').dialog({
autoOpen: false,
width: 600,
height: 400,
modal: true,
resizable: false,
draggable: false,
title: 'Advanced Search',
close: function() {
$("#advanced_search .start_date").datepicker('hide');
$("#advanced_search .end_date").datepicker('hide');
}
});
$('.adv_search').click(function() {
$('#advanced_search').dialog('open');
});
});
Here's an all-inclusive approach that's slightly better, simpler selectors and the date pickers aren't created until the dialog is actually opened, so if a user never goes into it, less script running:
$(function() {
$('#advanced_search').dialog({
autoOpen: false,
width: 600,
height: 400,
modal: true,
resizable: false,
draggable: false,
title: 'Advanced Search',
close: function() {
$("#advanced_search .start_date").datepicker('hide');
$("#advanced_search .end_date").datepicker('hide');
},
open: function(event, ui) {
$(".start_date, .end_date", ui).datepicker({
dateFormat: 'dd/mm/yy',
showButtonPanel: true,
duration: 0,
constrainInput: true,
showOn: 'button',
buttonImage: '/img/icons/50.png',
buttonImageOnly: true
});
}
});
$('.adv_search').click(function() {
$('#advanced_search').dialog('open');
});
});
Related
I open a jQuery Modal Dialog. I open a second Modal Dialog after the first one closes. When the second one closes I cannot interact with my page any more. Seems that there is some modal dialog still alive.
Can someone help?
Thanks
function modalFirst_Set() {
$('#modalFirst').dialog({
autoOpen: false,
dialogClass: 'DynamicDialogStyle',
resizable: true,
draggable: true,
modal: true,
width: 400,
height: 120,
title: "My First Modal",
open: function (type, data) {
var Page = 'PageFirst.aspx';
$('#modalFirst').load(Page);
},
close: function (event, ui) {
var retValue = $('#modalFirst_RetValue').val();
if (retValue=='X')
modalSecond_Show();
$(this).dialog('destroy');
modalFirst_Set();
}
});
}
function modalSecond_Set() {
$('#modalSecond').dialog({
autoOpen: false,
dialogClass: 'DynamicDialogStyle',
resizable: true,
draggable: true,
modal: true,
width: 400,
height: 120,
title: "My Second Modal",
open: function (type, data) {
var Page = 'PageSecond.aspx';
$('#modalFirst').load(Page);
},
close: function (event, ui) {
$(this).dialog('destroy');
modalSecond_Set();
}
});
}
No problem with this code. The problem was inside the pageSecond.aspx file.
a bit of assistance please.
Using YADCF with JQuery UI, and trying to include the functions: changeMonth: true, changeYear: true
In the example for JQueryUI this is what they use:
$( "#yourID" ).datepicker({
changeMonth: true,
changeYear: true,
With YADCF I am not sure how to add it. This is what my code looks like now:
.yadcf([
{column_number: 0, filter_type: "range_date",
datepicker_type: 'jquery-ui',
changeMonth: true,
changeYear: true,
filter_container_id: "external_filter_container"}
I have also tried inserting "changeMonth: true, changeYear: true," into
var datepickerDefaults = {
and separately targeting the YADCF id with
$( "#YADCFID" ).datepicker({
changeMonth: true,
changeYear: true,
So far no luck, any suggestions?
UPDATE: Although the form works the sorting does not.
Current Script:
var oTable;
$(document).ready(function () {
'use strict';
$('#example').dataTable({
"columnDefs": [{ "orderable": false, "targets": 0 }],
"order": [],
dom: '<"pos1"B><"pos2"li><"pos3"f>tp',
buttons: ['copy', 'csv', 'excel', 'pdf', 'print']
}).yadcf([
{column_number: 0, filter_type: "range_date",
filter_container_id: "external_filter_container",
filter_plugin_options: {
changeMonth: true,
changeYear: true,
dateFormat: "dd/mm/yy"
}
}
]);
SyntaxHighlighter.all();
});
and the html:
<tr>
<td>21/06/2017</td>
</tr>
<tr class="t-two">
<td>21/06/2017</td>
</tr>
The search result returns wrong months i.e. 02/02/2017 when I select range 01/06/2017 - 02/06/2017
You should use the filter_plugin_options attribute for that
Like this:
.yadcf([
{
column_number: 0,
filter_type: "range_date",
//datepicker_type: 'jquery-ui', this one is redundant because its the default value anyway
filter_container_id: "external_filter_container",
filter_plugin_options: {
changeMonth: true,
changeYear: true
}
}
])
I have 2 datepickers one for dateend and another for datestart.
I have a button in the html when you click it a dialog-form is going to appear.
then a ask data and populate the elements in the modal form. the modal form has date end and date start. but it seems the datestart is the only one populated. pls help. i really dont know what is wrong, stuck for more than 4days
<script type="text/javascript">
$(document).ready(function () {
$("#dialog-form").dialog({
autoOpen: false,
show: "drop", //explode
hide: "clip",
autoResize: true,
height: '500',
width: 'auto',
draggable: false,
modal: true,
resizable: false
});
$('input[type="button"]').click(function () {
var buttonHolder = $('input[type="button"]');
$("#dialog-form").dialog("open");
$("#timeStart").timepicker({});
$("#dateStart").datepicker({
defaultDate: "+1w",
dateFormat: "yy/mm/d",
changeMonth: true,
changeYear: true,
numberOfMonths: 3,
minDate: new Date(), // min date should be date of today or the date which he set as startdate
onClose: function () { //selectedDate should be value. i think. problem lies in the selected.
$("#dateEnd").datepicker("option", "minDate", $(this).val());
}
});
$("#dateEnd").datepicker({
defaultDate: "+1w",
dateFormat: "yy/mm/d",
changeMonth: true,
changeYear: true,
numberOfMonths: 3,
onClose: function () {
$("#dateStart").datepicker("option", "maxDate", $(this).val()); //$(this).val()
}
});
$.ajax({
type: "POST",
dataType: "json",
url: "<?php echo site_url('ajax/getEventOfModal'); ?>",
data: {
id: $(this).attr('id'),
username: "<?php echo $this->session->userdata('email'); ?>"
},
success: function (data) {
$("#event_id").attr('value', buttonHolder.attr('id'));
$("#event_name").attr('value', data['name']);
$("#event_loc").text(data['loc']);
$("#event_desc").text(data['desc']);
$("#timeStart").timepicker('setTime', data['timeStart']);
var queryDate = data['dateStart'],
dateParts = queryDate.match(/(\d+)/g)
realDate = new Date(dateParts[0], dateParts[1] - 1, dateParts[2]); // months are 0-based!
$('#dateStart').datepicker('setDate', realDate);
var queryDate2 = data['dateEnd'],
dateParts2 = queryDate2.match(/(\d+)/g)
realDate2 = new Date(dateParts2[0], dateParts2[1] - 1, dateParts2[2]); // months are 0-based!
$('#dateEnd').datepicker('setDate', realDate2);
}
});
});
});
</script>
Try removing the defaultdate from the jquery datepicker.
Following is my JS:
ShowHoverServerImageModalWindow: function () {
$("#divSettings").dialog({
width: 200,
height: 200,
modal: false,
title: "Server Image",
autoOpen: false,
closeOnEscape: true,
draggable: false,
resizeable: false,
/*position: "my position!!", */
buttons: [
{
text: "Close",
click: function () { $(this).dialog("close"); }
},
]
});
//Show the dialog
$("#divSettings").dialog('open');
},
I want the modal to be opened where my curser is at
How can i do that?
source: http://jqueryui.com/demos/dialog/ and http://docs.jquery.com/Tutorials:Mouse_Position
$("#divSettings").dialog({
... //your previous code
position: [e.pageX, e.pageY]
});
Easily found on google.
or just before you trigger the pop-up:
EDIT: now include the trigger.
$(document).click(function (e) {
$("#divSettings").dialog('option', 'position', [e.pageX, e.pageY]);
$("#divSettings").dialog('open');
});
I am playing with Jquery UI
I create a dialog on the fly from a DIV, i gave this DIV and ID and a button to call a closeDialog Function
It works fine as shown on this example
http://jsbin.com/ubovej
The problem I am having, is that if I d load a page THAT contains the BUTTON. The button will not work
as in:
$("<div id='mydialog1'>").dialog({
autoOpen: false,
modal: false,
width: 740,
height: 840,
title: 'Dialog1 = dynamic',
open: function(e, ui){
$(this).load(myUrl);
}
});
If this is the button Click Event code then
autoOpen: false,
should be
autoOpen: true,
EDIT: If you don't want it opened til you click the button then:
Do this when you want the dialog created.
var $dialog = $("<div id='mydialog1'>").dialog({
autoOpen: false,
modal: false,
width: 740,
height: 840,
title: 'Dialog1 = dynamic',
open: function(e, ui){
$(this).load(myUrl);
}
});
and do this after they click the button (only after the dialog is created)
$("button_selector").click(function () {
$dialog.dialog("open");
});
EDIT: Try changing
function closeDialog1(){
alert('closing Dialog1');
window.parent.$('#mydialog1').dialog('close');
return false;
}
to
function closeDialog1(){
alert('closing Dialog1');
$('#mydialog1').dialog('close');
return false;
}
Or a better way to do this might be
$("<div id='mydialog1'>").dialog({
autoOpen: false,
modal: false,
width: 740,
height: 840,
title: 'Dialog1 = dynamic',
open: function(e, ui){
$(this).load('dialogtest1a.html');
},
buttons: {
"Close" : function () {
$(this).dialog("close");
}
}
});
Does the button that closes the dialog HAVE TO be in the page you are loading?