$(function(){
// Dialog
$('#dialog').dialog({
autoOpen: false,
width: 600,
buttons: {
"Ok": function() {
$(this).dialog("close");
},
"Cancel": function() {
$(this).dialog("close");
}
}
});
// Dialog Link
$('#dialog_link').click(function(){
$('#dialog').dialog('open');
return false;
});
//hover states on the static widgets
$('#dialog_link, ul#icons li').hover(
function() { $(this).addClass('ui-state-hover'); },
function() { $(this).removeClass('ui-state-hover'); }
);
});
i m use dialog box jquery in which i want use datepicker
it show me outsde of the dialog box.....thats problem....
<div id="dialog" title="Find Patient">
<p>
<table style="table-layout: fixed; width: 550px;">
<tr>
<td><label class="form-item-label form-item-label-right">Patient Id :</label> </td>
<td><input type="text" name="byId" id="byId" style="width: 90%" /></td>
<td><a class="button" href="#"><span>Find</span></a></td>
</tr>
<tr>
<td><label class="form-item-label form-item-label-right">Patient`s Name :</label></td>
<td><input type="text" name="byName" id="byName" style="width: 90%"/></td>
<td><a class="button" href="#"><span>Find</span></a></td>
</tr>
<tr>
<td></td>
<td><input type="text" id="dob" name="dob" style="width: 90%"></td>
<td><a class="button" href="#"><span>Find</span></a></td>
</tr>
</table>
</p>
</div>
when i m use the datepicker Jquery in last row of table in dialog box
load my html page Datepicker is load on page first
I dont know if this is your solution, but try this out if you are tend to use the Jquery datepicker you should add it to the element directly on load mabye and not on focus, it will append when you focus the textbox anyway. Notice the line of code $('#dob').datepicker();
$(function () {
// Dialog
$('#dialog').dialog({
autoOpen: false,
width: 600,
buttons: {
"Ok": function () {
$(this).dialog("close");
},
"Cancel": function () {
$(this).dialog("close");
}
}
});
$('#dob').datepicker();
// Dialog Link
$('#dialog_link').click(function () {
$('#dialog').dialog('open');
return false;
});
//hover states on the static widgets
$('#dialog_link, ul#icons li').hover(
function () { $(this).addClass('ui-state-hover'); },
function () { $(this).removeClass('ui-state-hover'); }
);
});
Related
I would like to get tabs in a dialog box. Here's the code :
HTML :
<div id="box_form1">
<div id="dialog" title="Tab data">
<form>
<fieldset class="ui-helper-reset">
<label for="tab_title">Title</label>
<input type="text" name="tab_title" id="tab_title" value="Tab Title" class="ui-widget-content ui-corner-all">
<label for="tab_content">Content</label>
<textarea name="tab_content" id="tab_content" class="ui-widget-content ui-corner-all">Tab content</textarea>
</fieldset>
</form>
</div>
<button id="add_tab">Add Tab</button>
<div id="tabs">
<ul>
<li>TOTAL <span class="ui-icon ui-icon-close" role="presentation">Remove Tab</span></li>
</ul>
<div id="tabs-1">
<table>
<thead>
<tr>
<th>title</th>
<th>2015</th>
</tr>
</thead>
<tbody>
<tr>
<td>INV</td>
<td>1000</td>
</tr>
</tbody>
</table>
</div>
</div>
JAVASCRIPT :
$(document).ready(function () {
$('#box_form1').dialog({
title: "test",
autoOpen: false,
height: 600,
width: 600,
modal: true,
});
$('#module_ppi').button().click(function (e) {
$('#box_form1').dialog('open');
});
var tabTitle = $("#tab_title"),
tabContent = $("#tab_content"),
tabTemplate = "<li><a href='#{href}'>#{label}</a> <span class='ui-icon ui-icon-close' role='presentation'>Remove Tab</span></li>",
tabCounter = 2;
var tabs = $("#tabs").tabs();
// modal dialog init: custom buttons and a "close" callback resetting the form inside
var dialog = $("#dialog").dialog({
autoOpen: false,
modal: true,
buttons: {
Add: function () {
addTab();
$(this).dialog("close");
},
Cancel: function () {
$(this).dialog("close");
}
},
close: function () {
form[0].reset();
}
});
// addTab form: calls addTab function on submit and closes the dialog
var form = dialog.find("form").submit(function (event) {
addTab();
dialog.dialog("close");
event.preventDefault();
});
// actual addTab function: adds new tab using the input from the form above
function addTab() {
var label = tabTitle.val() || "Tab " + tabCounter,
id = "tabs-" + tabCounter,
li = $(tabTemplate.replace(/#\{href\}/g, "#" + id).replace(/#\{label\}/g, label)),
tabContentHtml = tabContent.val() || "Tab " + tabCounter + " content.";
tabs.find(".ui-tabs-nav").append(li);
tabs.append("<div id='" + id + "'><p>" + tabContentHtml + "</p></div>");
tabs.tabs("refresh");
tabCounter++;
}
// addTab button: just opens the dialog
$("#add_tab")
.button()
.click(function () {
dialog.dialog("open");
});
// close icon: removing the tab on click
tabs.delegate("span.ui-icon-close", "click", function () {
var panelId = $(this).closest("li").remove().attr("aria-controls");
$("#" + panelId).remove();
tabs.tabs("refresh");
});
tabs.bind("keyup", function (event) {
if (event.altKey && event.keyCode === $.ui.keyCode.BACKSPACE) {
var panelId = tabs.find(".ui-tabs-active").remove().attr("aria-controls");
$("#" + panelId).remove();
tabs.tabs("refresh");
}
});
});
http://jsfiddle.net/y25zw254/1/
The problem is : when I add a tab, the content of all tabs display.
How can I fix it ?
Thanks
You can have a look at this solution
$(document).ready(function() {
$("div#tabs").tabs();
$("button#add-tab").click(function() {
var num_tabs = $("div#tabs ul li").length + 1;
$("div#tabs ul").append(
"<li><a href='#tab" + num_tabs + "'>#" + num_tabs + "</a></li>"
);
$("div#tabs").append(
"<div id='tab" + num_tabs + "'>#" + num_tabs + "</div>"
);
$("div#tabs").tabs("refresh");
});
});
http://jsfiddle.net/axrwkr/ujUu2/
In this I am adding a tab on click of a button you can extend that inside your dialog box.
I'm trying to make a custom binding based on this code, http://jsfiddle.net/rniemeyer/WpnTU/ , Mine after a field checkbox is selected then open a jQueryUI dialog. Here is the code: http://jsfiddle.net/superjohn_2006/UFEg6/ , another question is it posible to acomplish this without a template.
<table>
<tbody data-bind="foreach: records">
<tr data-bind="foreach: fields">
<th align="left">
<input type="checkbox" data-bind="checked: chkedValue" /><span data-bind=" text: field"></span>
</th>
</tr>
<tr data-bind="foreach: fields">
<th align="left"><a data-bind="click: $root.addFormatting" href="#">Add Formatting</a></th>
</tr>
<tr data-bind="foreach: row">
<td data-bind="text: value"></td>
</tr>
</tbody>
</table>
<div id="details" data-bind="jqDialog: { autoOpen: false, resizable: false, modal: true }, template: { name: 'editTmpl', data: selectedField }, openDialog: selectedField">
</div>
<script id="editTmpl" type="text/html">
<p>
<label>Selected Field: </label>
<span data-bind="value: field" />
</p>
<button data-bind="jqButton: {}, click: $root.accept">Accept</button>
<button data-bind="jqButton: {}, click: $root.cancel">Cancel</button>
</script>
**The model
// custom binding
ko.bindingHandlers.jqDialog = {
init: function(element, valueAccessor) {
var options = ko.utils.unwrapObservable(valueAccessor()) || {}; // initialize a jQuery UI dialog
$(element).dialog(options);
// handle disposal
ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
$(element).dialog("destroy");
});
}
};
//custom binding handler that opens/closes the dialog
ko.bindingHandlers.openDialog = {
update: function(element, valueAccessor) {
var value = ko.utils.unwrapObservable(valueAccessor());
if (value) {
$(element).dialog("open");
} else {
$(element).dialog("close");
}
}
};
//custom binding to initialize a jQuery UI button
ko.bindingHandlers.jqButton = {
init: function(element, valueAccessor) {
var options = ko.utils.unwrapObservable(valueAccessor()) || {};
//handle disposal
ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
$(element).button("destroy");
});
$(element).button(options);
}
};
var resultsData = [
{ fields: [{ field: "Field1", chkedValue: false }, { field: "Field2", chkedValue: false }] },
{ row: [{ value: "1" }, { value: "True" }] },
{ row: [{ value: "2" }, { value: "False" }] }
];
var TableModel = function (records) {
var self = this;
self.records = ko.observableArray(ko.utils.arrayMap(records, function (record) {
return { fields: ko.observableArray(record.fields), row: ko.observableArray(record.row) };
}));
self.selectedField = ko.observable();
self.addFormatting = function (formatToAdd) {
self.selectedField();
};
};
this.accept = function() {
},
this.cancel = function() {
}
ko.applyBindings(new TableModel(resultsData));
the following couple of lines need to be changed.
span data-bind="value: field"
for:
span data-bind="text: $data.field"
and,
self.selectedField();
for:
self.selectedField(formatToAdd);
modified code is in the same jsFiddle, jus add: /1/
to the end of the url address.
<div id="dialog"></div>
<table>
<tr>
<td style="text-align: right">
#Html.ActionLink("Craete New Set1", "CreateNewSet1", "ClaimAuditAdmin", null, new{ #class = "openDialog", data_dialog_id = "emailDialog", data_dialog_title = "Create New Claim Audit Set"})
</td>
<td>
</td>
</tr>
$.ajaxSetup({ cache: false });
$(document).ready(function () {
$(".openDialog").live("click", function (e) {
e.preventDefault();
// $(".divContainer")
// $("<div></div>")
$("#dialog")
// .addClass("dialog")
.attr("id", $(this).attr("data-dialog-id"))
.appendTo("body")
.dialog({
title: $(this).attr("data-dialog-title"),
close: function () { $(this).remove() },
modal: true,
height: 325,
width: 325,
draggable: true,
resizable: false,
position: 'center',
scrollable:false
})
.load(this.href);
});
$(".close").live("click", function (e) {
e.preventDefault();
$(this).closest(".dialog").dialog("close");
});
});
Jquery PopUp in MVC showing in Chrome but not in IE.Also No issues showing in IE.
Try this once, Basically, you 'load' the content from the other page first.
$("#dialog")
.load(this.href)
.dialog({
autoOpen: false
}).open();
or
var link = this.href;
$("#dialog")
.dialog({
open: function (event, ui) {
$(this).load(link);
},
});
I'm pretty new to jQuery and UI, and I'm having two issue with the autocomplete, and I suspect they're related. When I select an item in the list, the value, not the label, is displayed in the input. Second, the autocomplete will not close. When I step through my code, the select function gets called, and I see my label, not the value, displayed in the input, as I want. Unfortunately, the close function gets called (twice), and the ui.item.value replaces the label in the input and the autocomplete doesn't close.
My autocomplete code, along with the input HTML, is below. If it matters, the autocomplete is nested in a jQueryUI dialog.
HTML:
<input id="id_projectid" type="text" class="projEntryControl ui-autocomplete-input ui-corner-all" name="projectid" autocomplete="off"></input>
AutoComplete:
$('#id_projectid').autocomplete({
source: function(request, response) {
$.ajax({
url: "/chargeback/projList/" + $('#id_departmentid').val(),
dataType:"json",
data: {
project_startsWith: request.term
},
success: function(data) {
response( $.map( data.results, function( item ) {
return {
label: item.projectName,
value: item.id
}
}));
}
});
},
minLength: 3,
select: function(event, ui) {
$('#id_projectid').val(ui.item.label);
},
open: function() {
$( '#id_projectid' ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
},
close: function() {
$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
}
});
EDIT: Adding more code as requested.
Here's the javascript that sets up the dialog, and connects the buttons to open the dialog
function setupProjectEntryDialog() {
$( "#addPEForm" ).dialog({
autoOpen: false,
height: 490,
width: 376,
modal: true,
buttons: {
"Save": function() {
var bValid = true;
allFields.removeClass( "ui-state-error" );
bValid = bValid && checkRegexp( hrsWorked, /^(?!\d{3})(?![2-9]\d)(?!1[1-9])(10|[1-9]{1})(.\d{0,2})?$/, "Please enter a valid number of hours worked." );
if ( bValid ) {
//save the changes to the database
var dataArray = $("#peUpdateForm").serializeArray();
var ed = new Object();
ed.name = "entryDateId";
ed.value = $("#entryDateId").text();
dataArray.push(ed);
if ($("#projEntryId").val() != "") {
var pe = new Object();
pe.name = "projEntryId";
pe.value = $("#projEntryId").val();
dataArray.push(pe);
}
$.post('/chargeback/savepe/', dataArray, function(data){
alert(data.msg);
//reload the project entries and total hours worked
showProjectEntries($('.entryDate.selected'));
getTotalHoursForEntryDate($('.entryDate.selected'));
}, "json");
//close the window
$( this ).dialog( "close" );
$('#id_projectid').autocomplete("destroy");
}
},
Cancel: function() {
$( this ).dialog( "close" );
$('#id_projectid').autocomplete("destroy");
}
},
close: function() {
allFields.val( "" ).removeClass( "ui-state-error" );
}
});
//connect the add new button
$("#addNewPEButton").click(function() {
$( "#addPEForm" ).dialog( "open" );
});
//hook up the add new project entry form submittal
$("#addNewPE").submit(function() {
addProjectEntry($(this));
return false;
});
//connect the delete Project Entry button
$('#deletePEButton').click(function() {
deleteProjectEntry($('.peRow.selected'));
return false;
});
//connect the row click method to the function
$('.peRow').click(function() {
peRowWasClicked($(this));
});
$('.peRow').dblclick(function() {
peRowWasDoubleClicked($(this));
})
}
Here's the javascript that loads the Dialog using a Django form and template to generate the HTML.
function addProjectEntry(anED) {
//ensure all peRows are not selected and disable the delete project entry button
$('.peRow').removeClass('selected');
$('#deletePEButton').attr('disabled', true);
//disable newFavoriteFromPEButton
$('#newFavoriteFromPEButton').attr('disabled', true);
//get the id of the selected entry date and strip the ed_ from it
$selectedED = $(".entryDate.selected");
var edId = $selectedED[0].id.split("_");
$("#addPEForm").load("/chargeback/cb_timeentry/newPE/" + edId[1], function() {
//connect the variables to the newly loaded html
connectDialogVariables();
//connect the project filtering to the department change
/*$("#id_departmentid").change(function() {
getProjectsForDepartment();
});*/
//connect the project and program number autocompletes to the controls
$('#id_projectid').autocomplete({
source: function(request, response) {
$.ajax({
url: "/chargeback/projList/" + $('#id_departmentid').val(),
dataType:"json",
data: {
project_startsWith: request.term
},
success: function(data) {
response( $.map( data.results, function( item ) {
return {
label: item.projectName,
value: item.id
}
}));
}
});
},
minLength: 3,
select: function(event, ui) {
$('#id_projectid').val(ui.item.label);
$(this).close();
return false;
},
open: function() {
$( '#id_projectid' ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
},
close: function() {
$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
}
});
});
}
This is the HTML after the ajax call completes, and the above javascript completes. The autocomplete begins the search when typing in the correct text input, and is positioned correctly, but isn't part of the form.
<div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable ui-resizable ui-dialog-buttons" style="outline: 0px none; z-index: 1002; position: absolute; height: auto; width: 376px; top: 66px; left: 297.5px; display: block;" tabindex="-1" role="dialog" aria-labelledby="ui-id-9">
<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
<span id="ui-id-9" class="ui-dialog-title">Project Entry Update</span>
<a href="#" class="ui-dialog-titlebar-close ui-corner-all" role="button">
<span class="ui-icon ui-icon-closethick">close</span>
</a>
</div>
<div id="addPEForm" class="ui-dialog-content ui-widget-content" style="width: auto; min-height: 0px; height: 367px;" scrolltop="0" scrollleft="0"><form action="" id="peUpdateForm" method="post">
<div style="display:none"><input type="hidden" value="BTrLZBVfA2ltExq3OUU5015BVxPKO9lL" name="csrfmiddlewaretoken"></div>
<p><label for="id_departmentid">Department:</label>
<select name="departmentid" class="projEntryControl" id="id_departmentid">
<option selected="selected" value="">Choose a Department</option>
<option value="1">ABND</option>
<option value="2">ATT</option>
<option value="3">AVI</option>
<option value="4">CCS</option>
<option value="5">PBW</option>
</select></p>
<p>
<label for="id_projectid">Project:</label>
<input type="text" name="projectid" class="projEntryControl ui-autocomplete-input" id="id_projectid" autocomplete="off">
<span role="status" aria-live="polite" class="ui-helper-hidden-accessible"></span>
</p>
<p>
<label for="id_progNumId">Program Number:</label>
<input type="text" name="progNumId" class="projEntryControl" id="id_progNumId">
</p>
<p>
<label for="id_hoursWorked">Hours Worked:</label>
<input type="text" id="id_hoursWorked" maxlength="5" class="projEntryControl" value="0.0" name="hoursWorked">
</p>
<p>
<label for="id_notes">Notes:</label>
<textarea name="notes" cols="40" rows="10" id="id_notes"></textarea
</p>
<p style="display:none;" id="entryDateId">1</p>
<p style="display:none;" id="projEntryId"></p>
</form>
</div>
<div class="ui-resizable-handle ui-resizable-n" style="z-index: 1000;"></div>
<div class="ui-resizable-handle ui-resizable-e" style="z-index: 1000;"></div>
<div class="ui-resizable-handle ui-resizable-s" style="z-index: 1000;"></div>
<div class="ui-resizable-handle ui-resizable-w" style="z-index: 1000;"></div>
<div class="ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se ui-icon-grip-diagonal-se" style="z-index: 1000;"></div>
<div class="ui-resizable-handle ui-resizable-sw" style="z-index: 1000;">
</div><div class="ui-resizable-handle ui-resizable-ne" style="z-index: 1000;"></div>
<div class="ui-resizable-handle ui-resizable-nw" style="z-index: 1000;"></div>
<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix">
<div class="ui-dialog-buttonset">
<button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false">
<span class="ui-button-text">Save</span>
</button>
<button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false">
<span class="ui-button-text">Cancel</span>
</button>
</div>
</div>
</div>
<div class="ui-widget-overlay" style="width: 979px; height: 567px; z-index: 1001;"></div>
<ul class="ui-autocomplete ui-menu ui-widget ui-widget-content ui-corner-all" id="ui-id-11" tabindex="0" style="z-index: 1003; display: none;">
</ul>
I have a table and within the first <td> is a hidden <div>. I want to show the div using a jQuery ui dialog which I have the following code
example tr
<tr>
<td>
<div id="subscriberNote" style="display: none;">
long message text........
</div>
long mess...
</td>
<td>
<a id="notedetails" href="#">View note</a>
</td>
</tr>
jQuery
function subscriberNotes_onload() {
$("#subscriber_notes tr").bind("click", function() {
openDialog(this);
});
}
function openDialog(row){
$(row).closest("tr").find("td:eq(0)").find("#subscriberNote").dialog({
title: "Message",
modal: true,
width: 600,
height: 530,
buttons: {
"OK": function () { $(this).dialog("close"); }
}
}).show();
}
After the dialog is shown and closed it is removing the hidden div and so has nothing to show until the page is refreshed.
Make the last function like:
function openDialog(row){
$(row).closest("tr").find("td:eq(0)").find("#subscriberNote").dialog({
title: "Message",
modal: true,
width: 600,
height: 530,
buttons: {
"OK": function () { $(this).dialog("close"); }
},
close: function(){ $(this).dialog("destroy")}
}).show();
}
According to the docs it should revert to its original state.