When you have a Lookup column you may find some results you don’t want your end users to select, for instance in my example below, the column name is ‘Team Name’ which is also a required field. This column basically shows every single team.
What the script below does is prevents the user from saving the form if “Human Resources” or “–Select a Team–” have been chosen. It also provides text under the specific column to show an error message “Please select a different Team”. (last section of the code below to see where to place this).
The code below can be amended to be a Choice column rather than a lookup by changing the getTagFromIdentifierAndTitle(“select”,”Lookup”,”Team Name Required Field”); to your column.
<script>
function getTagFromIdentifierAndTitle(tagName, identifier, title) { function PreSaveAction(){ if(blockName.indexOf(‘–Choose a Team–‘)==0||blockName.indexOf(‘Human Resources’)==0){ </script> <td width=”400px” valign=”top” class=”ms-formbody”> |
Details below of the tags & identifiers per column type
Column Type | Tag | Identifier |
Single Line of Text | input | text |
Multiple Line of Text | input | textarea |
Lookup | select | Lookup |
… | … | … |