Search This Blog

Monday, 10 August 2020

Bootstrap zipcode validation for country US and Canada

----------------------------------------------------------------------------------------------

$('#formID').bootstrapValidator({

       feedbackIcons: {

           valid: 'glyphicon glyphicon-ok',

           invalid: 'glyphicon glyphicon-remove',

           validating: 'glyphicon glyphicon-refresh'

       },

       fields: {

           InputZip: {

               validators: {

               callback: {

                        message: 'The zip is not valid postal code',

                        callback: function (value, validator, $field) {

                        var country = $("#InputCountry").val();                      

                        switch (country) {

                            case 'CA':

                                return /^(?:A|B|C|E|G|H|J|K|L|M|N|P|R|S|T|V|X|Y){1}[0-9]{1}(?:A|B|C|E|G|H|J|K|L|M|N|P|R|S|T|V|W|X|Y|Z){1}\s?[0-9]{1}(?:A|B|C|E|G|H|J|K|L|M|N|P|R|S|T|V|W|X|Y|Z){1}[0-9]{1}$/i.test(value);

                            case 'US':

                            default:

                                return /^\d{4,5}([\-]\d{4})?$/.test(value);

                        }

                        }

                    }

               }

           }

          

       }

   });

----------------------------------------------------------------------------------------------

Sunday, 9 August 2020

Kendo Grid - Add tooltip to Kendo Grid Header

       

 ----------------------------------------------------------------------

     var gridName = "myKendoGridID";

      $("#"+gridName+" thead tr th").each(function(e){
$(this).attr('title', $(this).text());
      });

----------------------------------------------------------------------

Monday, 4 March 2013

Change cell value in jqGrid


To change the value of a cell in a jqGrid, you can use the setCell method provided by jqGrid. 
Here’s how you can do it:

Syntax:

$("#grid").jqGrid('setCell', rowid, columnname, value, cssclass, properties)

Parameters:

  • rowid: The ID of the row where the cell is located.
  • columnname: The name of the column (the name property from the colModel).
  • value: The new value to set in the cell.
  • cssclass: (Optional) A class to apply to the cell.
  • properties: (Optional) An object containing any additional properties to set on the cell.

  • Examples:
    ----- ---------- ---------- ---------- ---------- ---------- ----------
        
         $("#gridId").jqGrid('setCell', rowId,'qty', '12345');          

    ----- ---------- ---------- ---------- ---------- ---------- ----------
                                                OR
    ----- ---------- ---------- ---------- ---------- ---------- ----------
     
        var rowData = $('#gridId').jqGrid('getRowData', rowId);
        rowData.qty = '12321';
        $('#gridId').jqGrid('setRowData', rowId, rowData);

    ----- ---------- ---------- ---------- ---------- ---------- ----------

    Change JqGrid Row Color


     $("#rowId").css("background","#FFEAEA");
     $("#rowId").css("color", "black");

    Thursday, 20 December 2012

    JQGrid Custom Validation

    How to check whether EmailId already exists or not

    colModel:[{name:'emailId',index:'emailId', width:200,editable:true, sorttype:'int',editrules:{email:true, required:true, custom:true, custom_func:checkvalid}}],

    +
    function checkvalid(value, colname)
    {                                       
          var gr = jQuery("#list2").getGridParam('selarrrow');
          if(gr=='')
          {
                var flag = false;
                var allRowsInGrid=$("#list2").getGridParam("records");
                for(i=1;i<=allRowsInGrid;i++)
                {
                     var rowId = $("#list2").getRowData(i);
                     var emailId = rowId['emailId'];
                     if(emailId == value)
                     {
                           flag = true;
                     }
                }
                if(flag == true)
                     return [false,"Email Id: Email already exist, Please enter a different email ID."];
                else
                     return [true,""];
          }
          else
          {
              return [true,""];
           }
    }  

    onSelectRow event in jqgrid

     

    The example below specifies the action to take when a row is selected. 
     
    var lastSel;
    jQuery("#gridid").jqGrid({
    ...
       onSelectRow: function(id){ 
          if(id && id!==lastSel){ 
             jQuery('#gridid').restoreRow(lastSel); 
             lastSel=id; 
          } 
          jQuery('#gridid').editRow(id, true); 
       },
    ...
    });

    String comparison in javascript

    JavaScript String Compare

    Comparing strings in JavaScript is quite easy, as long as you know about the equals operator and the JavaScript If Statement. This is all you need to know to find out if two strings of your choosing are equal.

    Comparing one String to another String

    Below we have created a fake authentication system and use an if statement to see if the user's name will grant them access to a special message.

    JavaScript Code:

    <script type="text/javascript">
    var username = "Agent006";
    if(username == "Agent007")
     document.write("Welcome special agent 007"); 
    else
     document.write("Access Denied!"); 
    document.write("<br /><br />Would you like to try again?<br /><br />");
    
    // User enters a different name
    username = "Agent007";
    if(username == "Agent007")
     document.write("Welcome special agent 007"); 
    else
     document.write("Access Denied!"); 
    
    </script>
    

    Display:

    Access Denied!

    Would you like to try again?

    Welcome special agent 007
    Be sure you realize that when you are comparing one string to another, you use two equals operators "==" instead of just one "=". When you use two equals operators, it means you are comparing two values.
    In this case, the English translation of our program would be: "If username is equal to Agent007, then print out a welcome message; otherwise, access is denied."

    Case Insensitive String Compare

    Above, we used a case sensitive compare, meaning that if the capitalization wasn't exactly the same in both strings, the if statement would fail. If you would like to just check that a certain word is entered, without worrying about the capitalization, use the toLowerCase function.

    JavaScript Code:

    <script type="text/javascript">
    var username = "someAgent";
    if(username == "SomeAgent")
     document.write("Welcome special agent"); 
    else
     document.write("Access Denied!"); 
     
    // Now as case insensitive
    document.write("<br /><br />Let's try it with toLowerCase<br /><br />");
    if(username.toLowerCase() == "SomeAgent".toLowerCase())
     document.write("Welcome special agent"); 
    else
     document.write("Access Denied!"); 
    </script>
    

    Display:

    Access Denied!

    Let's try it with toLowerCase

    Welcome special agent