jQueryUI Autocomplete won't close on select - jquery-ui

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>

Related

Polygerrit plugin does not always show a changeAction button

I am writing a plugin for gerrit 2.16.12 that should show a button for starting an extended build stage on our Jenkins for a particular change. My problems are two.
It seems that to show the button I need to reload the page once. If I go back to the page later, I still need to do a reload.
If I press the action, the plugin shows a popup with some values filled in. From there I can submit the build with the parameters needed. But if I press the button a second time, the values are not filled in and the submit button in the form does not work.
Perhaps they are related, not sure. Any ideas?
This is my plugin html file:
<dom-module id="build-all-stages">
<script>
//alert("Gerrit plugin is being installed");
console.log("Loading build-all-stages plugin");
Gerrit.install(plugin => {
changeActions = plugin.changeActions();
key = changeActions.add(changeActions.ActionType.CHANGE, 'Build All Stages');
changeActions.addTapListener(key, ev => {
plugin.popup("build-all-stages-mod").then(popup => {
el = document.querySelector('gr-change-metadata');
if (el == null) {
alert("Could not find the gr-change-metadata element");
popup.close();
return;
}
change = el.change;
revision = el.revision;
bast = document.querySelector('build-all-stages-mod');
if (bast == null) {
alert("Could not find the plugin element.");
popup.close();
return;
}
bast.addEventListener('done', () => {
console.log("Closing popup");
popup.close();
});
bast.gerrit_project = change.project;
bast.gerrit_branch = change.branch;
bast.gerrit_newrev = change.branch;
bast.gerrit_refname = change.branch;
bast.gerrit_refspec = revision.ref;
bast.gerrit_patchset_revision = revision.commit.commit;
});
});
});
console.log("Loaded build-all-stages plugin");
</script>
</dom-module>
<dom-module id="build-all-stages-mod">
<template>
<h2>Build all stages in Jenkins</h2>
Please make sure that you are allready logged in to Jenkins and then verify the values below pefore pressing submit:
<form id="jenkins_form"
method="post"
on-submit="handleDone"
target="_blank"
action="https://jenkins.mycompany.com/job/[[gerrit_branch]]/job/Stage0-All_pipeline_stages-Test/buildWithParameters">
<table>
<tr><td>GERRIT_PROJECT: </td><td> <input name="GERRIT_PROJECT" size=40 value="[[gerrit_project]]"/></td></tr>
<tr><td>GERRIT_BRANCH: </td><td> <input name="GERRIT_BRANCH" size=40 value="[[gerrit_branch]]"/></td></tr>
<tr><td>GERRIT_NEWREV: </td><td> <input name="GERRIT_NEWREV" size=40 value="[[gerrit_newrev]]"/></td></tr>
<tr><td>GERRIT_REFNAME: </td><td> <input name="GERRIT_REFNAME" size=40 value="[[gerrit_refname]]"/></td></tr>
<tr><td>GERRIT_REFSPEC: </td><td> <input name="GERRIT_REFSPEC" size=40 value="[[gerrit_refspec]]"/></td></tr>
<tr><td>GERRIT_PATCHSET_REVISION: </td><td> <input name="GERRIT_PATCHSET_REVISION" size=40 value="[[gerrit_patchset_revision]]"/></td></tr>
</table>
<input name="userFlag" value="true" type="hidden"/>
<button type="submit" value="Submit">Submit</button>
<button id="jenkins_cancel" type="button" on-click="handleDone">Cancel</button>
</form>
</template>
<style>
:host {
display: block;
border: 1px solid black;
padding: 5px;
}
td {
padding: 3px;
}
</style>
<script>
gerrit_type = {
type: String,
value: "",
notify: false,
reflectToAttribute: true
};
gerrit_type = String;
Polymer({
is: 'build-all-stages-mod',
properties: {
gerrit_project: gerrit_type,
gerrit_branch: gerrit_type,
gerrit_newrev: gerrit_type,
gerrit_refname: gerrit_type,
gerrit_refspec: gerrit_type,
gerrit_patchset_revision: gerrit_type,
},
handleDone: function() {
this.fire('done', null);
}
});
</script>
The plugin should listen to the showChange event so the button will display automatically.
Gerrit.install(plugin => {
plugin.on('showchange', params => {
console.log(params)
const changeActions = plugin.changeActions();
changeActions.add('revision', 'display name');
//...
}
}

Multiple dialog function inside loop

i try to make a multiple dialog form from some data in the database but when i clicked the button, the dialog form not showed
i use PHP increment numeric to differentiate the attribute id
then i use for to sync the id on my php code with the id on jquery code
when i try on jsfiddle, it says "Functions declared between loop referencing an outer scoped variable may lead to confusing semantics"
this is my php code:
<button class="btn btn-danger" id="create-user<?php echo $no2++; ?>">Buka Blokir</button>
<div id="dialog-form<?php echo $no++; ?>" title="Create new user">
<p class="validateTips">All form fields are required.</p>
<form>
<fieldset>
<label for="reason">Reason</label>
<input type="text" name="reason" id="reason" value="Jane Smith" class="text ui-widget-content ui-corner-all">
<input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
</fieldset>
</form>
</div>
and thisis my jquery code:
$( function() {
var dialog, form,
reason = $( "#reason" ),
allFields = $( [] ).add( reason ),
tips = $( ".validateTips" );
function updateTips( t ) {
tips
.text( t )
.addClass( "ui-state-highlight" );
setTimeout(function() {
tips.removeClass( "ui-state-highlight", 1500 );
}, 500 );
}
function checkLength( o, n, min, max ) {
if ( o.val().length > max || o.val().length < min ) {
o.addClass( "ui-state-error" );
updateTips( "Length of " + n + " must be between " +
min + " and " + max + "." );
return false;
} else {
return true;
}
}
function checkRegexp( o, regexp, n ) {
if ( !( regexp.test( o.val() ) ) ) {
o.addClass( "ui-state-error" );
updateTips( n );
return false;
} else {
return true;
}
}
function unBlock() {
var valid = true;
allFields.removeClass( "ui-state-error" );
valid = valid && checkLength( reason, "reason", 6, 80 );
if ( valid ) {
$( "#users tbody" ).append( "<tr>" +
"<td>" + dasar.val() + "</td>" +
"</tr>" );
dialog.dialog( "close" );
}
return valid;
}
for (var i = 1; i < 50; i++) {
dialog = $( "#dialog-form"+i ).dialog({
autoOpen: false,
height: 400,
width: 350,
modal: true,
buttons: {
"Unblock": unBlock,
Cancel: function() {
dialog.dialog( "close" );
}
},
close: function() {
form[ 0 ].reset();
allFields.removeClass( "ui-state-error" );
}
});
}
form = dialog.find( "form" ).on( "submit", function( event ) {
event.preventDefault();
addUser();
});
for (var b = 1; b < 50; b++) {
$( "#create-user"+b ).button().on( "click", function() {
dialog.dialog( "open" );
});
}
} );
I think you're making it overly complicated. Consider the following code.
$(function() {
var reasons = $("[id^='reason']"),
tips = $(".validateTips");
function updateTips(t) {
tips
.text(t)
.addClass("ui-state-highlight");
setTimeout(function() {
tips.removeClass("ui-state-highlight", 1500);
}, 500);
}
function checkLength(o, n, min, max) {
if (o.val().length > max || o.val().length < min) {
o.addClass("ui-state-error");
updateTips("Length of " + n + " must be between " +
min + " and " + max + ".");
return false;
} else {
return true;
}
}
function checkRegexp(o, regexp, n) {
if (!(regexp.test(o.val()))) {
o.addClass("ui-state-error");
updateTips(n);
return false;
} else {
return true;
}
}
$("[id^='dialog-form']").dialog({
autoOpen: false,
height: 400,
width: 350,
modal: true,
buttons: {
"Unblock": function() {
var valid = true;
reasons.removeClass("ui-state-error");;
var reason = $(this).find("[id^='reason']");
valid = valid && checkLength(reason, "reason", 6, 80);
if (valid) {
/*
$("#users tbody").append("<tr>" +
"<td>" + dasar.val() + "</td>" +
"</tr>");
*/
$("[id^='dialog-form']").dialog("close");
}
return valid;
},
Cancel: function() {
$(this).dialog("close");
}
},
close: function() {
$(this).find("form")[0].reset();
reasons.removeClass("ui-state-error");
}
});
$("div[id^='dialog-form'] form").on("submit", function(e) {
e.preventDefault();
/*
addUser();
*/
});
$("button[id^='create-user']").on("click", function(e) {
var selfId = $(this).attr("id");
var d = selfId.match(/\d+/g).map(Number);
var dlg = $("#dialog-form-" + d);
dlg.dialog("open");
});
});
<link rel="stylesheet" href="//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>
<button class="btn btn-danger" id="create-user-1">Buka Blokir</button>
<div id="dialog-form-1" title="Create new user">
<p class="validateTips">All form fields are required.</p>
<form>
<fieldset>
<label for="reason-1">Reason</label>
<input type="text" name="reason" id="reason-1" value="Jane Smith" class="text ui-widget-content ui-corner-all">
<input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
</fieldset>
</form>
</div>
<button class="btn btn-danger" id="create-user-20">Buka Blokir</button>
<div id="dialog-form-20" title="Create new user">
<p class="validateTips">All form fields are required.</p>
<form>
<fieldset>
<label for="reason-20">Reason</label>
<input type="text" name="reason" id="reason-2" value="John Smith" class="text ui-widget-content ui-corner-all">
<input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
</fieldset>
</form>
</div>
With a selector that encompasses more than one element, you can still assign UI Widgets to it. You just have to understand how to use this and $(this) to your advantage.

Jquery UI selectable: Define multiple selectable objects DYNAMICALLY

I really need some help on the following: I am currently developing a shopping cart. Whenever a new product is appended to shopping cart it becomes a button. This button (product) is used to add some modifiers to each product. The button definition can be seen below:
var productAdded = $('<tr class="product" data-real_id = "'+ id +'" data-id_modal="'+ mod_id +'"><td class="product_name2"><button href="#0" class="button2" style="background-color:#00a65a;" data-comment="" data-modifiers="" data-span_mod = "" data-real_id = "'+ id +'" data-id_modall="'+ mod_id +'" id = "'+ comment_id +'">' + product_name + '</button></td><td class="quantity"><span class="select"><select id="cd-product-'+ id +'" name="quantity"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option></select></span></td><td class="price">' + product_price + '</td><td><i class="fa fa-trash-o fa-2x" aria-hidden="true"></i></td></tr>');
Whenever each of the product's button is pressed a JQUERY UI dialog window is opened whic contains a JQUERY UI SELECTABLE object:
<div class="modal fade" id="modal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header"></div>
<div class="modal-body" style="margin-top:5px;">
<div style="width:100%; float:left;">
<label for="modifier">Τροποποιητές: </label>
<span id="select-result" data-modifiers_span=""></span>
<ol id="selectable" class="txt-modifiers">
<!-- INSERTED BY JQUERY DYNAMICALLY PER PRODUCT -->
</ol>
</div>
<label for="comment">Σχόλιο: </label>
<textarea rows="4" cols="50" name="comment" id="comment" value="" class="form-control txt-comment" style="vertical-align: top;"></textarea>
</div>
<div class="modal-footer" style="margin-top:10px;">
<button class="btn btn-success btn-save" data-id="" data-id_modall="">Αποθήκευση</button>
<button class="btn btn-default" data-dismiss="modal">Κλείσιμο</button>
</div>
</div>
</div>
</div>
As you can see below the modifiers of the product are extracted using AJAZ+PHP from mysql database:
$(document).on('click touchstart','.button2',function(e){
e.preventDefault();
var id = $(this).attr('id'); //Get element id
var real_id = $(this).attr('data-real_id');
var comment = $(this).attr('data-comment'); //Get comment
var modifiers = $(this).attr('data-modifiers'); //Get modifiers
var teeee = $(this).attr('data-id_modall');
$('#modal .txt-comment').val(comment);
$('#modal .btn-save').attr('data-id',id);
$('#modal .btn-save').attr('data-id_modall',teeee);
//alert(modifiers);
if (modifiers.length == 0)
{
$("#selectable").html('<img src="images/ajax-loader.gif" />');
var request = $.ajax({
url: 'http://127.0.0.1:8080/Food%20Ball/backup/FoodBall%20Site%20form_dt_2/Food%20Ball%20Site/get_item_modifiers.php?item_id=' + real_id,
cache: false,
dataType: 'json',
contentType: 'application/json; charset=utf-8',
type: 'get',
success: function(data) {
if( data.result != 'Not'){
$("#selectable").html(data.options);
$('#modal .txt-modifiers').val(data.options);
}
else{ $("#selectable").html('Δεν υπάρχουν!');
$('#modal .txt-modifiers').val('Δεν υπάρχουν!'); }
}
});
}
else { $('#modal .txt-modifiers').val(modifiers); $("#selectable").html(modifiers);}
$('#modal').dialog('open');
});
And the selectable object:
$(function () {
$('#selectable').on('touchstart mousedown', function(e) {e.metaKey = true;})
.selectable({
selected: function(event, ui) {
var result = $( "#select-result").empty();
$( ".ui-selected", this ).each(function() {
result.append($(this).attr('data-product_modifier') + ', ');
});
},
unselected: function(event, ui){
var result = $( "#select-result");
$( ".ui-unselected", this ).each(function() {
result.remove($(this).attr('data-product_modifier') + ', ');
});
}
});
});
And finally the "Save" button for each dialog modal window:
$(document).on('click touchstart','.btn-save',function(e){
e.preventDefault();
var id =$(this).attr('data-id'); //Get data id
var comment =$('.txt-comment').val(); //get the comment
var modifiers =$('.txt-modifiers').val(); //get the modifier
//update the "order" note column modal
var note_modal = '#' + $(this).attr('data-id_modall'); //get the id row of the order modal
var note_modal2 = '#2' + $(this).attr('data-id_modall'); //get the id row of the order modal
$(note_modal).find('#note_modal').text(comment+'--'+modifiers);
$(note_modal2).find('#note_modal2').text(comment+'--'+modifiers);
$('#'+id).attr('data-comment',comment);
$('#'+id).attr('data-modifiers',modifiers);
//Save it in data base..s
$('#modal').dialog('close');
$('.txt-comment').val('');//clear text area
$('.txt-modfiers').val('');//clear text area
});
$(document).on('click','.btn-default',function(e){
e.preventDefault();
//Save it in data base..s
$('#modal').dialog('close');
$('.txt-comment').val('');//clear text area
$('.txt-modfiers').val('');//clear text area
});
My problem is that if i add more than one products to my cart the selected modifiers appear for all products. How can i have multiple selectable objects defined dynamically and save each product's selected modifiers?
If anyone can help on this i will really appreciate it
Thank you
ok solved it:
simply put the following code within the successful return of the Ajax call:
var request = $.ajax({
url: 'http://127.0.0.1:8080/Food%20Ball/backup/FoodBall%20Site%20form_dt_2/Food%20Ball%20Site/get_item_modifiers.php?item_id=' + real_id,
cache: false,
dataType: 'json',
contentType: 'application/json; charset=utf-8',
type: 'get',
success: function(data) {
if( data.result != 'Not'){
$("#selectable").html(data.options);
$('#modal .txt-modifiers').val(data.options);
$( "#selectable" ).selectable({
stop: function() {
result_mod = $( ".select_result" ).empty();
$( ".ui-selected", this ).each(function() {
result_mod.append(' +' + $(this).attr('data-product_modifier'));
//array_mod = array_mod + (' +' + $(this).attr('data-product_modifier'));
$('#modal .select_result').val(result_mod);
});
}
});
}
else{ $("#selectable").html('Δεν υπάρχουν!');
$('#modal .txt-modifiers').val('Δεν υπάρχουν!');
$( ".select_result").html('');
$('#modal .select_result').val('');
}
}
});

jQuery of Dialog and datepicker

$(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'); }
);
});

How to apply the shake effect to a dialog with an embedded form

I'm newbie on this, I'm trying to apply the shake effect to a dialog that has an embedded form but not success on this.
When I try to trigger the effect
$("#restore_password").effect("shake",
{times: 3}, 80);
only the fields inside the form tag is taking the effect but the dialog box itself doesn't.
My div
<html>
<body>
<div id="restore_password" title="Confirmation code" class="ui-widget-content ui-corner-all" >
<form> <fieldset> <label for="code">Code</label> <input type="text" name="codecon" id="codecon" class="text ui-widget-content ui-corner-all" /> </fieldset>
</form>
</div>
</body>
</html>
My dialog
$("#restore_password").dialog({
height: 220,
width: 310,
autoOpen: false,
modal: true,
draggable: false,
resizable: false,
show: 'puff',
hiden: 'puff',
buttons: {
"Confirm": function(){
$("#change_password").dialog('open');
},
"Cancel": function(){
$(this).dialog('close');
$("#forgot_data").dialog('close');
$("#dialog-form").dialog('open');
setTimeout(function(){
$("#name").focus();
}, 800);
}
},
close: function() {
allFields.val('').removeClass('ui-state-error');
}
});
Any ideas?, it would be helpful.
Nalum's solution worked, but was a little ugly. Try this one:
$('#restore_password').parent().effect("shake", {times: 3}, 80);
$(...).dialog(...); creates a new element without an id.
e.g.
<div id="testingDiv">...</div>
becomes
<div style="..." class="..." tabindex="..." role="dialog" aria-labelledby="ui-dialog-title-testingDiv">
...
<div id="testingDiv">...</div>
...
</div>
So your code is working. What you need to do is target the dialog div e.g.
$('div[aria-labelledby=ui-dialog-title-testingDiv]').effect("shake", {times: 3}, 80);

Resources