Posts

Donate

Check If T-SQL Field Value Is A UniqueIndentifier In Select Case Statement

In the event that you need to check a T-SQL field value if it's a GUID or UniqueIdentifier, the same procedure is used in applying the logic in a where clause. SELECT CartObjectID, CartName, CartQuantity, CASE When TDD.FieldData like REPLACE ( '00000000-0000-0000-0000-000000000000' , '0' , '[0-9a-fA-F]' ) Then ( Select CartValue From tblCartList where ListID = TDD.FieldData ) ELSE TDD.FieldData END As FieldData

Bootstrap Table Column Width And Word-Break Not Working Using Data-Width Attribute

Hello All, One of the issue that I had with Bootstrap Tables by Wenzhixin is that you can't set the width directly using data-width attribute given the code below. <th data-field= "description" data-sortable= "true" data-searchable= "true" data-width= "350px" > Description </th> After doing some research and experiments, the solution that worked for me is to set the Bootstrap Table table-layout style to fixed. Bootstrap Table CSS #tblEmployeeDependents { table-layout : fixed ; } And use data-class attribute instead of data-width property to set the column width. HTML Code <th data-field= "description" data-sortable= "true" data-searchable= "true" data-class= "tdDescription" > Description </th> Data-Class CSS Style .tdDescription { width : 350px ; word - break : break - word; }

Bootstrap Modal Black Background Not Closing After Form Is Submitted

Hello fellow developers! Normally, when closing a Bootstrap Modal, the black background also disappear. However, if the closing of Bootstrap Modal is triggered by a close or button event fired from a "Yes" button of jQuery UI dialog the bootstrap dialog is closed but the black background of the bootstrap modal is still visible. The solution that I came up with is to close the modal dialog before the call to submit the form in the Yes callback function of the jQuery UI Dialog. function fnOpenNormalDialog($form) { var form = $form; $( '<div id="divConfirm"></div>' ).dialog({ resizable: false , modal: false , title: "Confirm Shipping" , height: 150, width: 350, open: function () { $( this ).html( "Confirm that this part is ready to be shipped?" ); }, buttons: { "Yes" : function () { $( this ).dialog( 'close' ); Callback( true , form); }, "No" : function () {

How To Set Or Position BlockUI On Top Of jQuery UI Dialog

Good day! I have this requirement to show an overlay message using BlockUI on top of a jQuery UI Dialog. Assuming that these two are modals, I can't show the progress message on top of the jQuery UI Dialog. I found the solution in stackoverflow that is to set the z-index of BlockUI to 2000. $.blockUI({ message: '<h3>Saving of record in progress...</h3>' , baseZ: 2000 });

Restrict Remote Validation In ASP.NET MVC Edit Mode.

Hello, In data entry operations, we normally validate user input if they exist in the database, if yes we throw some kind of exception or error message that the data they entered already exists in the database. But in scenario like editing of existing information, we don't want this to happen. So to restrict the remote validation in ASP.NET MVC, I found the fix from stack Remote validation restrict for edit controller method but modified the logic in the controller which is to return a JSON rather than a bool value. The code modifications are as follows. Edit View or Edit Partial View: Add another HiddenField for Initial Product Code used for Comparison. @Html.Hidden("InitProductCode", Model.ProductCode) Model: Add AdditionalFields in Remote Attribute. [Display(Name = "Product Code")] [Required(ErrorMessage = "ProductCode is required")] [Remote("CheckProductCode", "Products", HttpMethod = "POST", ErrorMessage = &q

Bootstrap Modal Hide Not Working On Form Submit In ASP.NET MVC

Good afternoon! I'm working on a ASP.NET MVC which uses the oldest version of Bootstrap which 3.0. Normally when working with modals, the hide() function works if using updated versions of the Bootstrap given the code below. The snippet should close the modal after a form has been submitted but this doesn't work as expected when working with the oldest version. $( "#modal-add" ).on( "submit" , "#form-add" , function (e) { e.preventDefault(); var form = $( this ); $.ajax({ url: form.attr( "action" ), method: form.attr( "method" ), data: form.serialize(), success: function (data) { $( "#modal-add" ).modal( 'hide' ); //close modal function $( "#tblEmployee" ).bootstrapTable( 'load' , data); showAlert( 'Saving of record successful!' , 'success' ); }, error: function (er) { showAlert( 'Error saving record. Please try again later.' , 'dan

How To Sort Dates With Invalid Values In JavaScript

Given the sorting function below to sort dates, this doesn't add checking for invalid date values. In return, the sorting doesn't do any effect on the data provided. var DateSortWithValidation = function (a, b) { var dateA = new Date(a); var dateB = new Date(b); if (dateA < dateB) return -1; if (dateA > dateB) return 1; return 0; }; So I made a little modification to the function using isNan() for date validation which sorts the dates properly. var DateSortWithValidation = function (a, b) { var dateA = new Date(a); var dateB = new Date(b); if (isNaN(dateA)) { return 1; } else if (isNaN(dateB)) { return -1 } else { if (dateA < dateB) return -1; else if (dateA > dateB) return 1; else return 0; } }; Usage of the function. $(document).ready( function () { var dates = [ new Date( '08/25/2018' ), new Date( 'test' ), new Date( '09/15/2018' ), new Date( &#

Bootstrap-Table-Export.js Not Exporting Bootstrap Table Data

Normally, exporting a Bootstrap-Table by Wenzhixin using Bootstrap-Table-Export.js plugin works. But in my case, it's returning an empty document whether Excel,CSV, XML or JSON format. I did some debugging on the plugin itself and found out that it doesn't export if the main table contains child table(s). A fix that I came up was to remove the child tables from the table object before passing it to the tableExport.js plugin. The solutions is applied in the doExport() function of Bootstrap-Table-Export.js plugin. doExport = function () { //remove child table elements. var length = that.$tableBody.children( 'table' ).find( 'table' ).length; if (length > 0) { that.$tableBody.children( 'table' ).find( 'table' ).remove(); } that.$el.tableExport($.extend({}, that.options.exportOptions, { type: type, escape: false })); };

Script Selector With Specified Attribute Not Found When Using jQuery In ASP.NET MVC

I have this script below that will insert a dynamically defined script tag next to an existing script element in an ASP.NET MVC page. $(document).ready( function () { script.type = "text/javascript" ; script.src = '/Scripts/bootstrap3.2.0.js' ; $(script).insertAfter( 'script[src*="bootstrap.js"]' ); $( 'script[src*="bootstrap.js"]' ).attr( 'src' , '' ); }); Using the script above, I wasn't able to achieve the output since it can't locate the particular script tag. Upon investigating the production site, it appears that the scripts are bundled and the code above has no effect. With slight modification of the code to check if a script is bundled, I managed to get the inserting of script working. $(document).ready( function () { var script = document.createElement( 'script' ); script.type = "text/javascript" ; script.src = '@Url.Content("~/Scripts/bootstrap3.2.0.js")&

MongoDB Getting UTC Date Instead Of Local Date In ASP.NET MVC

Image
Hello all! When inserting local dates in MongoDB and retrieving them using C#, you might wonder why the date returned is inconsistent with the values stored in the database. Well, MongoDB treats those dates as UTC. So to display those dates as local, there are several solutions. Option one is to change the BsonElement attribute of a date property [BsonElement] [Required(ErrorMessage = "Activity Date required")] [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)] public DateTime ActivityDate { get ; set ; } to BsonDateTimeOptions and set it's kind to local. [BsonDateTimeOptions(Kind = DateTimeKind.Local)] [Required(ErrorMessage = "Activity Date required")] [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)] public DateTime ActivityDate { get ; set ; } Option two is to retain the BsonElement attribute of the date property. [BsonElement] [Required(ErrorMessage = "A

Donate