SPAUTOCOMPLETE 2014-02 release issue - Required Field Title issue

Jan 28, 2015 at 4:41 PM
Edited Jan 28, 2015 at 5:50 PM
Problem Description:
Problem 1:
I have 4 textfields with spautocomplete feature being used.
two fields especially Material Number and Material Description can populate each other.
Material Number is a required field and this caused the issue with the cumulative update
Material Number Required Field - SPautocomplete does not work
Material Description - SPautocomplete works fine
spservices 0.7.2


Problem 2: I thought i will need to use the latest spservices and try and when i do that.
Material Number Required Field - SPautocomplete works fine
Material Description - SPautocomplete does not work
spservices latest release 2014-02


Here is the code ..... This was all working fine until the Sharepoint was updated to June or Dec CU.
  1. <script language="javascript" type="text/javascript" src="/sites/MM/SPServicesJS/jquery-1.11.2.js"></script>
    <script language="javascript" type="text/javascript" src="/sites/MM/SPServicesJS/jquery-1.11.2.min.js"></script>
    <script language="javascript" type="text/javascript" src="/sites/MM/SPServicesJS/jquery.SPServices-2014.02.js"></script>
    <script language="javascript" type="MMt/SPServicesJS/jquery.SPServices-2014.02.min.js">
    PopulateMaterialDescriptionFromMaterialNumber("Material Information List","MaterialNumber","Material Number");
    
// FUNCTION TO POPULATE MATERIAL DESCRIPTION FROM NUMBER
function PopulateMaterialDescriptionFromMaterialNumber(liname, scname, clname)
{

    jQuery().SPServices.SPAutocomplete
        ({  
        sourceList: liname,
        sourceColumn: scname,
        columnName: clname,
        ignoreCase: true,
        highlightClass: "ms-bold",
        numChars: 1,
        filterType: 'Contains',
        slideDownSpeed: "fast",
        debug: true
        });

    jQuery('li').live('click', function()
    {

        var container_id2 = $(this).parent().attr('id');
        if (container_id2 == "SPAutocomplete_MaterialNumber") 
        {    

            var strMaterialNumber = jQuery("input[title='Material Number']").val();

            var CamlMaterialNumber = " ";
            CamlMaterialNumber = "<Query><Where><Eq><FieldRef Name='MaterialNumber' /><Value Type='Text'>" + strMaterialNumber + "</Value></Eq></Where></Query>"
            jQuery().SPServices(
            {
                   operation: "GetListItems",
                   async: false,
                   listName: liname,
                   CAMLViewFields: "<ViewFields><FieldRef Name = 'MaterialDescription' /><FieldRef Name = 'MaterialNumber' /></ViewFields>",
                   CAMLQuery: CamlMaterialNumber,

                   completefunc: function (xData, Status) 
                   {

                        jQuery(xData.responseXML).SPFilterNode("z:row").each(function()
                    {

                        var liHtml1 = jQuery(this).attr("ows_MaterialDescription");                                         
                        jQuery("input[title='Material Description']").val(liHtml1);


                    });           
                }
            });
        }   
    });


}










Marc,

I have been using jquery.SPServices-0.7.2.min.js for long time. Recently 3 months ago I implemented a solution for 6 custom new forms where i use spautocomplete a lot for text fields.

Recently after some update.... required fields stopped working and non required are working Thats one issue.

with your latest spservices it is doing viceversa.

Thanks,
Avinash
Coordinator
Jan 28, 2015 at 5:22 PM
Avinash:

Can you post your code? Are you getting any script errors? Can you tell what's breaking?

M.
Jan 28, 2015 at 5:54 PM
The way i can fix temporarily is updating my function as shown below but I would like to use your latest spservices2014-02. Is it compatible with sp2010?. Because spautocomplete was not working with your latest release...basically not giving me the dropdown. It worked ok for required field

// FUNCTION TO POPULATE MATERIAL DESCRIPTION FROM NUMBER
function PopulateMaterialDescriptionFromMaterialNumber(liname, scname, clname)
{

    jQuery().SPServices.SPAutocomplete
        ({  
        sourceList: liname,
        sourceColumn: scname,
        columnName: clname,
        ignoreCase: true,
        highlightClass: "ms-bold",
        numChars: 1,
        filterType: 'Contains',
        slideDownSpeed: "fast",
        debug: true
        });

    jQuery('li').live('click', function()
    {

        var container_id2 = $(this).parent().attr('id');
        //alert(container_id2);
        if (container_id2 == "SPAutocomplete_undefined") 
        {    

            var strMaterialNumber = jQuery("input[title='Material Number Required Field']").val();

            var CamlMaterialNumber = " ";
            CamlMaterialNumber = "<Query><Where><Eq><FieldRef Name='MaterialNumber' /><Value Type='Text'>" + strMaterialNumber + "</Value></Eq></Where></Query>"
            jQuery().SPServices(
            {
                   operation: "GetListItems",
                   async: false,
                   listName: liname,
                   CAMLViewFields: "<ViewFields><FieldRef Name = 'MaterialDescription' /><FieldRef Name = 'MaterialNumber' /></ViewFields>",
                   CAMLQuery: CamlMaterialNumber,

                   completefunc: function (xData, Status) 
                   {

                        jQuery(xData.responseXML).SPFilterNode("z:row").each(function()
                    {

                        var liHtml1 = jQuery(this).attr("ows_MaterialDescription");                                         
                        jQuery("input[title='Material Description']").val(liHtml1);


                    });           
                }
            });
        }   
    });


}
// FUNCTION TO POPULATE MATERIAL DESCRIPTION FROM NUMBER
Coordinator
Jan 28, 2015 at 6:07 PM
Oh, OK. It's that damn required field problem. Let me take a look. I thought I had it fully fixed in 2014.02.

Sounds like it is working with required fields, but not fields that aren't required?

BTW, I recommend using jQueryUI's autocomplete. It's what I was emulating when I built SPAutocomplete, and I never took it as far as they did. Here's an example:
  $("input.ticker-lookup").autocomplete({
    source: function(request, response) {

      var tickerList = [];

      // Whenever the user types a key, refresh the available Tickers
      $().SPServices({
        operation: "GetListItems",
        async: false,
        listName: "Tickers",
        CAMLQuery: "<Query><Where><Or>" +
          "<Contains><FieldRef Name='Title' /><Value Type='Text'>" + escapeXml(request.term) + "</Value></Contains>" +
          "<Contains><FieldRef Name='TickerName' /><Value Type='Text'>" + escapeXml(request.term) + "</Value></Contains>" +
          "</Or></Where></Query>",
        CAMLViewFields: "<ViewFields><FieldRef Name='Title'/></ViewFields>",
        CAMLRowLimit: 0,
        completefunc: function (xData, Status) {

          // If we have matching items, populate the autosuggest
          $(xData.responseXML).SPFilterNode("z:row").each(function() {

            // For each returned item, push all the values we want into the array
            tickerList.push({
              label: $(this).attr("ows_Title") + " - " + $(this).attr("ows_TickerName"),
              value: $(this).attr("ows_Title") + " - " + $(this).attr("ows_TickerName"),
              tickerName: $(this).attr("ows_TickerName"),
              ticker: $(this).attr("ows_Title")
            });
          });
        }
      });
      response(tickerList);
    },
    minLength: 1,

    // When the user makes a selection
    select: function( event, ui ) {
      $(this).addClass("ui-autocomplete-loading");
      $(this).attr("disabled", true);
      window.location = "Ticker.aspx?Ticker=" + escapeUrl(ui.item.ticker);
    }
  });
});
M.
Jan 28, 2015 at 6:33 PM
Thank you so much Mark. Now you know what I am talking about. Thats only one problem.

Second problem is how do I fix the existing issue where i use this code below. The main reason i use this is because some forms could have more than 1 text fields with spautocomplete and this code below allows me to make sure the action happens when a value is choosen.
Current issue with spservices 0.7.2
Material Description - If not a required field - spautocomplete_materialdescription
Material Number - If required field - spautocomplete_undefined


ALSO ONE THING I NEVER GOT TO TOLD YOU. THANK YOU SO MUCH FOR SPSERVICES. YOU ARE MORE THAN A ROCK STAR. IF THERE WAS A NOBEL PRIZE IN SHAREPOINT WORLD. I WOULD GIVE THAT TO YOU.

Code
jQuery().SPServices.SPAutocomplete
    ({  
    sourceList: liname,
    sourceColumn: scname,
    columnName: clname,
    ignoreCase: true,
    highlightClass: "ms-bold",
    numChars: 1,
    filterType: 'Contains',
    slideDownSpeed: "fast",
    debug: true
    });
jQuery('li').live('click', function()
{

    var container_id2 = $(this).parent().attr('id');
    //alert(container_id2);
    if (container_id2 == "SPAutocomplete_undefined") 
    {    
do something....... when value is selected in autocomplete
   }