Quantcast
Viewing all articles
Browse latest Browse all 6517

New Post: Global complex to simple lookups fields from the master page.

Hi Marc,

This may have a place in your library. The first section is the library portion and the last part demonstrates the callback that can be used when a value is selected from the dropdown. The rest is fairly obvious. Insert the empty option in the select and disable the save button if necessary until an option is selected.

$(document).ready (function() {

//create a namespace for our object

var noDefault = {};

// cache some key DOM elements

noDefault.titleElem = $("td.ms-formbody input[title='Title']")[0];

// Disable the calculate index column

noDefault.titleElem.disabled = true;

//Initialize our “required field” array

noDefault.lookupFlds=['Title', 'RequestID', 'CertID'];

noDefault.fldCnt = noDefault.lookupFlds.length;

// If first selection option not already "" then prepend it

noDefault.addEmpty = (function (selTitle) {

var fldElem = $("td.ms-formbody select[title='" + selTitle + "']");

// if bad field name passed, ignore it

if (typeof(fldElem[0]) != 'undefined') {

var selectID = '#'+ (fldElem[0].id);

var already = ($(selectID)[0][0].text === "");

if (!already) {

$(selectID).prepend("<option value=''></option>").val('');

}

}

});

// Return the text of the selected option for the Selection

noDefault.rqdValid = (function(selTitle) {

var fldElem = $("td.ms-formbody select[title='" + selTitle + "']");

if (typeof(fldElem[0]) != 'undefined') {

var selectID = '#'+ (fldElem[0].id);

var selectedOpt = selectID + ' :selected'

return $(selectedOpt).text();

}

});

// Check if ALL required fields have selected options.

noDefault.allRqdValid = (function() {

var valCnt = 0;

$.each(noDefault.lookupFlds, function(index, selTitle) {

var selText = noDefault.rqdValid(selTitle);

if (selText !== ""){

valCnt +=1;

}

});

return (valCnt === noDefault.fldCnt);

});

// If all required fields have selected text values, then enable the save button

noDefault.setSaveStatus = (function() {

var cmdSubmit = $('input[id$="_diidIOSaveItem"]');

var allRqdAreValid = noDefault.allRqdValid();

if (allRqdAreValid) {

$(cmdSubmit).removeAttr('disabled');

// this is a callback for validation success

if (typeof(reqdValidCallback) != 'undefined') {

// if it exists as a function call it.

reqdValidCallback.call();

}

}

else {

$(cmdSubmit).attr('disabled','disabled');

}

});

// This is the end of our object declaration

// Now apply the functions to the elements

// Iterate the required field array adding the empty node if not already found

$.each(noDefault.lookupFlds, function(index, selTitle) {

noDefault.addEmpty(selTitle);

});

noDefault.setSaveStatus();

// Add an event handler to validate the required fields after every change.

$("select[title=RequestID]").change(function() {

noDefault.setSaveStatus();

});

$("select[title=CertID]").change(function() {

noDefault.setSaveStatus();

});

function reqdValidCallback() {

// in our callback set our title to the calculated field

var requestElem = $("td.ms-formbody select[title='RequestID']");

var rqElemID = '#'+ (requestElem[0].id);

var reqOpt = rqElemID + ' :selected';

var reqSelOpt = $(reqOpt).text();

var certElem = $("td.ms-formbody select[title='CertID']");

var certElemID = '#'+ (certElem[0].id);

var certOpt = certElemID + ' :selected';

var certSelOpt = $(certOpt).text();

noDefault.titleElem.value = reqSelOpt + '-' + certSelOpt;

return;

}

});

</script>


Viewing all articles
Browse latest Browse all 6517

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>