mardi 24 février 2015

Problem while resetting the share point lockup value with 20+ items



I have a sharepoint lookup and a text box. On Text box changed event i want to reset the next lookup value to (None) and text box to empty.


Below is the code for the same. This code is working properly in Chrome but not in IE10. Can you please help me on this. I think the problem is with ResetDropdown Function . Below is the same.



function ResetDropDownList(lookupcolumnName,NumStoreColName)
{

if(getField('select',lookupcolumnName))
{
getField('input',NumStoreColName).value='';
$("select[title='"+ lookupcolumnName +"'] option:eq(0)").attr('selected','(None)');

}
else
{
var tempDDLName = "tempDDLName_" + lookupcolumnName;
var myElement = $('select[name="' + tempDDLName + '"]');
myElement.val(myElement.find('option').first().val());
getField('input',NumStoreColName).value='';
//$("input[title='"+ lookupcolumnName +"'] option:eq(0)").attr('selected','(None)');
//getField('input',NumStoreColName).value='';

}

}




<script src="http://ift.tt/1DNO8H9" type="text/javascript"></script>
<script src="http://ift.tt/1D76Sfu" type="text/javascript"></script>
<script type="text/javascript" >
$(document).ready(function()
{
$('.ms-lookuptypeintextbox').each(function()
{
OverrideDropDownList($(this).attr('title'));
});


HideInitialCol("Number of Stores 1","Co-op 2","Number of Stores 2");
HideInitialCol("Number of Stores 2","Co-op 3","Number of Stores 3");
HideInitialCol("Number of Stores 3","Co-op 4","Number of Stores 4");
HideInitialCol("Number of Stores 4","Co-op 5","Number of Stores 5");
HideInitialCol("Number of Stores 5","Co-op 6","Number of Stores 6");
HideInitialCol("Number of Stores 6","Co-op 7","Number of Stores 7");


NumberofStoreChangeVal("Number of Stores 1","Co-op 2","Number of Stores 2");
NumberofStoreChangeVal("Number of Stores 2","Co-op 3","Number of Stores 3");
NumberofStoreChangeVal("Number of Stores 3","Co-op 4","Number of Stores 4");
NumberofStoreChangeVal("Number of Stores 4","Co-op 5","Number of Stores 5");
NumberofStoreChangeVal("Number of Stores 5","Co-op 6","Number of Stores 6");
NumberofStoreChangeVal("Number of Stores 6","Co-op 7","Number of Stores 7");

});


function NumberofStoreChangeVal(NumStoreColName,hidelookup,hideNoofstorecol)
{

$("input[title='"+NumStoreColName+"']").change(function()
{
var NoStoreVals =$("input[title='"+NumStoreColName+"']").val();
if(NoStoreVals == "")
{
HideColumns(hidelookup,hideNoofstorecol,"True");
ResetDropDownList(hidelookup,hideNoofstorecol);
}
else
{
HideColumns(hidelookup,hideNoofstorecol,"False");
}
});
}


function HideInitialCol(NumStoreColNames,HideNextLookup,HideNextStoreCol)
{
var NoStoreVal =$("input[title='"+NumStoreColNames+"']").val();

if(NoStoreVal == "")
{
HideColumns(HideNextLookup,HideNextStoreCol,"True");

}
else
{
HideColumns(HideNextLookup,HideNextStoreCol,"False");
}

}
function HideColumns(LookUpcol,NumStoresCol,IsHide)
{

if(IsHide=="True")
{
$('nobr:contains("'+LookUpcol+'")').closest('tr').hide();
$('nobr:contains("'+NumStoresCol+'")').closest('tr').hide();


}
else
{
$('nobr:contains("'+LookUpcol+'")').closest('tr').show();
$('nobr:contains("'+NumStoresCol+'")').closest('tr').show();

}

}

function getField(fieldType,fieldTitle) {
var docTags = document.getElementsByTagName(fieldType);
for (var i=0; i < docTags.length; i++) {
if (docTags[i].title == fieldTitle) {
return docTags[i];
} }
return false;
}
function ResetDropDownList(lookupcolumnName,NumStoreColName)
{

if(getField('select',lookupcolumnName))
{
getField('input',NumStoreColName).value='';
$("select[title='"+ lookupcolumnName +"'] option:eq(0)").attr('selected','(None)');

}
else
{

$("input[title='"+ lookupcolumnName +"'] option:eq(0)").attr('selected','(None)');
getField('input',NumStoreColName).value='';
// var text = $(this).html();
// var tempDDLName = "tempDDLName_" + lookupcolumnName;

// $('#tempDDLName').find('option:first').attr('selected','(None)');
//$('#tempDDLName').find('option:first').attr('selected','(None)');
//$('#' + tempDDLName).find('option:first').attr('selected','(None)');

//$(#tempDDLName).find('option:first').attr('selected','(None)');


}


}


// Main Function
function OverrideDropDownList(columnName)
{

// Construct a drop down list object
var lookupDDL = new DropDownList(columnName);

// Do this only in complex mode...
if (lookupDDL.Type == "C")
{

// Hide the text box and drop down arrow
lookupDDL.Obj.css('display', 'none');
lookupDDL.Obj.next("img").css('display', 'none');

// Construct the simple drop down field with change trigger
var tempDDLName = "tempDDLName_" + columnName;
if (lookupDDL.Obj.parent().find("select[ID='" + tempDDLName + "']").length == 0)
{
lookupDDL.Obj.parent().append("<select name='" + tempDDLName + "' id='" + tempDDLName + "' title='" + tempDDLName + "'></select>");
lookupDDL.Obj.parent().find("select[ID='" + tempDDLName + "']").bind("change", function ()
{
updateOriginalField(columnName, tempDDLName);
});
}

// Get all the options
var splittedChoices = lookupDDL.Obj.attr('choices').split("|");

// get selected value
var hiddenVal = $('input[name=' + lookupDDL.Obj.attr("optHid") + ']').val()
if (hiddenVal == "0")
{
hiddenVal = lookupDDL.Obj.attr("value")
}

// Replacing the drop down object with the simple drop down list
lookupDDL = new DropDownList(tempDDLName);

// Populate the drop down list
for (var i = 0; i < splittedChoices.length; i++) {
var optionVal = splittedChoices[i];
i++;
var optionId = splittedChoices[i];

var selected = (optionId == hiddenVal) ? " selected='selected'" : "";
lookupDDL.Obj.append("<option" + selected + " value='" + optionId + "'>" + optionVal + "</option>");
}
}
}

// method to update the original and hidden field.
function updateOriginalField(child, temp) {
var childSelect = new DropDownList(child);
var tempSelect = new DropDownList(temp);

// Set the text box
childSelect.Obj.attr("value", tempSelect.Obj.find("option:selected").val());

// Get Hidden ID
var hiddenId = childSelect.Obj.attr("optHid");

// Update the hidden variable
$('input[name=' + hiddenId + ']').val(tempSelect.Obj.find("option:selected").val());
}

// just to construct a drop down box object. Idea token from SPServces
function DropDownList(colName)
{
// Simple - when they are less than 20 items
if ((this.Obj = $("select[Title='" + colName + "']")).html() != null) {
this.Type = "S";
// Compound - when they are more than 20 items
} else if ((this.Obj = $("input[Title='" + colName + "']")).html() != null)
{
this.Type = "C";
// Multi-select: This will find the multi-select column control on English and most other languages sites where the Title looks like 'Column Name possible values'
} else if ((this.Obj = $("select[ID$='SelectCandidate'][Title^='" + colName + " ']")).html() != null) {
this.Type = "M";
// Multi-select: This will find the multi-select column control on a Russian site (and perhaps others) where the Title looks like 'Выбранных значений: Column Name'
} else if ((this.Obj = $("select[ID$='SelectCandidate'][Title$=': " + colName + "']")).html() != null) {
this.Type = "M";
} else
this.Type = null;
} // End of function dropdownCtl

function MandateColumn(ColName, mandatory)
{

if(mandatory)
{
var spanTagmandate ="<span class=\"ms-formvalidation\"> *</span>",
newHtml = ColName;
newHtml += spanTagmandate;
$('nobr:contains('+ColName+')').html(newHtml);
}
else {

var myObj= $('nobr:contains('+ColName+')').find(".ms-formvalidation").remove();
}
}

</script>







0 commentaires:

Enregistrer un commentaire