Alert message when checkbox is not selected - jquery-ui
I am new to jquery and Jqgrid. I have problems displaying an alert message, when the checkbox is not selected in jqgrid, i.e i have declared the multiselect:true.
function initJqGridSearchSubProject(table,pager,msg,loadSelID,caption,chkMrk ){
$(table).empty();
$(table).GridUnload();
var mygrid =jQuery(table).jqGrid({
datatype: "local",
data:msg,
width: 1240,
scrollOffset:0,
height: 250,
colNames:['ID','PID','Project Folder Name','Sub Project Name','Responsible','Status','Last Updated On'],
colModel:[
{name:'id',index:'id',hidden:true, width:5, sorttype:"int", editable: false,resizable:false},
{name:'pid',hidden:true, width:5, sorttype:"int", editable: false,resizable:false},
{name:'projectFolderName', width:250, editable: true,formatter:'tsLinks'},
{name:'subProjectName', width:250, editable: true,formatter:'subProjectLinks'},
{name:'responsible', width:200, editable:false,resizable:false},
{name:'status', width:100,editable: true,stype:'select',edittype:"select",resizable:false,editoptions:{value:"ACTIVE:ACTIVE;INACTIVE:INACTIVE;DELETED:DELETED",readonly:false},editrules:{edithidden:false}},
{name:'lastUpdatedOn', width:200,editable: false,resizable:false,sorttype:'date',formatter:'date',formatoptions:{ srcformat: 'M d y H:i:s', newformat: 'd M y h:i A' }}
],
pager: pager,
rowNum:200,
rowList:[200,400,600,1000],
//rowTotal:2000,
//loadOnce:true,
//rownumbers:true,
gridview : true,
//sortname: 'lastUpdatedOn',
viewrecords: true,
//sortorder: "desc",
toppager:true,
multiselect:true,
singleselect: false,
//multiboxonly:true,
//toolbar: [true,'both'],
caption:caption,
hidegrid: false,
gridComplete:function(id){
//$(chkMrk).hide();
//alert('grid complete');
},
beforeSelectRow: function(rowid, e)
{
// reset check box selection only when user clicks on another checkbox
if($(e.target).is("input:checkbox"))
{
// reset/clear other checkboxes selection before making a latest clicked row's checkbox as selected
jQuery(table).jqGrid('resetSelection');
}
// Code To Disable Check Box Selection When User Selects by Clicking on A Row
return $(e.target).is("input:checkbox");
//return(true);
}
});
jQuery(table).jqGrid('navGrid',pager,{del:false,add:false,edit:false,search:false,refresh:true,cloneToTop:true,afterRefresh:function(){}},{},{},{},{});
jQuery(table).jqGrid('navButtonAdd', table+ '_toppager_left',{caption:"Add WO", buttonicon:"ui-icon ui-icon-plus",id:"SUBPROJID", onClickButton: function(){},position:"first",title:"Add WO"});
});
This is my whole code jqgrid...
I have a rows of fields with prjt names and subprjects names, where i use multiselect, to display the checkbox before the row for all fields, Its mandate that user should click one checkbox to show other page,where if user does not check, he should be shown an alert message to check any checkbox.
I hope that I undertand correct your requirements. You added custom button "Add WO" to the navigator bar and you need display alert message if no row is selected when the button are clicked or to redirect to another page if some row is do selected.
You can get the list of selected rows using $(this).jqGrid("getGridParam", "selarrrow") or using $(this).jqGrid("getGridParam", "selrow") inside of onClickButton, which will be called if the user click on the button. The internal parameter selrow represent the rowid of last selected row. If $(this).jqGrid("getGridParam", "selrow") is null then no row is selected. The call $(this).jqGrid("getGridParam", "selarrrow") get the value of another internal parameter "selarrrow" which is array of selected ids. If will be filled in case of usage multiselect:true.
So I think that you can display warning to the user if selrow is null or if selarrrow is empty array. If the need to redirect to another HTML page you can assign new value to location.href.
Use this in last line to uncheck last selected check box
jQuery(this).attr('checked', false);
Full code
jQuery(document).ready(function(){
jQuery('input:checkbox').change(
function(){
if (jQuery('input:checkbox:checked').length == jQuery('input:checkbox').length){
alert('Alert Text.');
jQuery(this).attr('checked', false);
}
});
});
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.
How to set focus to textbox on Onchange event of dropdown?
I have textbox whose visibility is controlled by value selected in telerik dropdown. Say if value selected is yes then textbox is visible else it hides. Now when value in dropdown set to Yes i am not able to set focus to that textbox. Only on pressing 'Tab' key focus moves over there but not as soon as textbox appears. I have tried this code: function OnDropDownChange(e){ if ($(this).val() === "Y") { $("#txtID").show(); $("#txtID").focus(); } } Any help will be appreciated.
Try this it can be work: $('#txtID').show('slow', function() { $(this).focus(); }); Reference
$("#txtID").show(400, function() { $(this).focus(); });
JqueryUI datepicker, buttontext as value
I am trying to get the buttontext of datepicker (which defaults to an ellipsis), to set itself as the value of the input. I have multiple datepickers on the page, and unlike my example below I have an icon instead of a text input. I would like the value itself to show on the tooltip that appears when you hover over the icon. I have tried - buttonText: $(this).val() as an option but it doesn't pick anything up Example - http://jsbin.com/unolot/3/ So my question - How do I get the buttontext of the datepicker input to match the value dynamically?
You have to handle two cases: When the selected date changes: use the onSelect event to change the button's title attribute On initial rendering: unfortunately, the datepicker does not implement the widget factory (yet) so there is no create event, you'll have to update the title attribute manually after the widget has initialized. Don't forget to set the default date of the picker to the initial value of the field, otherwise the default selected date is "today" Something like this: // as you have several instances, loops through them $(".deadline_picker_on").each(function() { var dt = $(this); dt.datepicker({ showOn: "button", buttonText: '', // set the default date to the value of the field defaultDate: dt.val(), duration: 100, dateFormat: 'yy-mm-dd', showOptions: { direction: 'right' }, onSelect: function(dateText, inst) { // on data selection, change the title attribute of the button $(this).next().attr('title', dateText); } }) // get the button (next element) .next() // set the title attribute with the formatted initial date from the picker .attr('title', $.datepicker.formatDate('yy-mm-dd', dt.datepicker('getDate'))); });
showing values instead of labels value in input field with jquery-autocomplete
i've got the following code taken and slightly modified by the original example page: http://jsfiddle.net/zK3Wc/21/ somehow, if you use the arrow down button to go through the list, it shows the values (digits) in the search field, instead of the label, but the code says, that on the select event, the label should be set as the value. what i would need is to display the label in the searchfield instead of the digits, but if i click on an item, it has the digit value in the url, the same when using the arrow down button. Ramo
Add a focus event: focus: function( event, ui ) { $( ".project" ).val( ui.item.label ); return false; }, http://jsfiddle.net/zK3Wc/26/
For me, I forgot to put return false; in the select: callback function
jQuery UI Dialog Queries + jQueryUI Queries
I have setup the following jQuery UI Dialog within my document.ready() section, i.e: $("#dialog").dialog({ autoOpen: false, bgiframe: true, resizable: false, modal: true, buttons: { 'Ok': function() { $(this).dialog("close"); } } }); 1) My question is which I am unsure of, is that within my javascript code, I have a counter, which when it hits a particular value, would like my dialog window to appear. Unsure how to achieve or trigger this? 2) Within the jQueryUI website, I am trying to download the "Custom Theme" from http://jqueryui.com/download/?themeParams=%3Fctl%3Dthemeroller but nothing seem to happen, i.e no dialog save box appears. Any ideas? Thanks.
1) If you want the dialog appear only when that condition is met, you should set the autoOpen option to false, later in your code, after you increment your counter variable, you should check its value and show it if the counter has the particular value you look for, i.e.: // ... counter++; if (counter == 100) { $('#dialog').dialog('open'); } // ... 2) To build your custom theme, use ThemeRoller.
First question: When you hit desired counter value do this: $("#dialog").dialog("open");