Home

Content Script Editor - Javascript Snippet

%3CLINGO-SUB%20id%3D%22lingo-sub-146943%22%20slang%3D%22en-US%22%3EContent%20Script%20Editor%20-%20Javascript%20Snippet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-146943%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20experimenting%20in%20an%20office%20365%20trial%20tenant%26nbsp%3Band%20have%20a%20requirement%20to%20show%20a%20popup%20message%20based%20on%20the%20value%20of%20a%20field%20in%20my%20EditForm.%20I%20am%20trying%26nbsp%3Bthe%20instructions%20listed%20on%26nbsp%3B%3CA%20title%3D%22Field%20Validation%20JavaScript%20Snippet%22%20href%3D%22https%3A%2F%2Fwww.dmcinfo.com%2Flatest-thinking%2Fblog%2Fid%2F9279%2Fsharepoint-form-validation-using-javascript-jquery%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.dmcinfo.com%2Flatest-thinking%2Fblog%2Fid%2F9279%2Fsharepoint-form-validation-using-javascript-jquery%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIt%20works%20fine%20the%20way%20it%20is%20and%20shows%20the%20error%20message%20if%20the%20field%20is%20left%20blank%20etc.%20But%20If%20I%20add%20a%20small%20code%2C%20as%20underlined%20below%2C%20then%20the%20nothing%20works%20and%20not%20even%20simple%20alert%20messages.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETruly%20appreciate%20any%20guidance.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CSCRIPT%20src%3D%22https%3A%2F%2Fcode.jquery.com%2Fjquery-latest.min.js%22%3E%3C%2FSCRIPT%3E%20%0A%3CSCRIPT%3E%20%0A%20function%20PreSaveItem()%20%7B%0A%20%20%20%20%20a%3A%20%3Breturn%20%22function%22%20%3D%3D%20typeof%20PreSaveAction%20%3F%20PreSaveAction()%20%3A%20true%0A%20%7D%0A%3C%2FSCRIPT%3E%20%0A%20%0A%3CSCRIPT%3E%20%0A%2F%2FWhen%20the%20user%20clicks%20'Save'%2C%20SharePoint%20will%20run%20this%20function%20%0Afunction%20PreSaveAction()%7B%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%2F%2FReturning%20true%20will%20cause%20the%20form%20to%20be%20submitted%2C%20false%20will%20prevent%20form%20submission%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3Bvar%20result%20%3D%20true%3B%20%0A%20%20%20%20alert(%22Test%22)%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%2F%2FClear%20out%20existing%20error%20messages%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%24('.errorMessage').remove()%3B%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%2F%2FSelect%20the%20input%20of%20a%20text%20field%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3Bvar%20textField%20%3D%20GetFieldByDisplayName(%22Title%22)%3B%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3Bvar%20column1Field%20%3D%20GetFieldByDisplayName(%22Column%201%22)%3B%20%0A%20%20%20%20alert%20(textField.val().trim())%3B%0A%0A%26amp%3Bamp%3Bamp%3Blt%3BU%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Blt%3BSTRONG%26amp%3Bamp%3Bamp%3Bgt%3B%20%20%20%20If%20!(textField.val().trim())%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%7B%0A%20%20%20%20%20%20%20alert(textField.val().trim())%0A%20%20%20%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20alert(%22Else%20Part%22)%0A%20%20%20%20%20%7D%3B%0A%26amp%3Bamp%3Bamp%3Blt%3B%2FSTRONG%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Blt%3B%2FU%26amp%3Bamp%3Bamp%3Bgt%3B%20%20%20%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%2F%2FCheck%20if%20the%20input%20is%20empty%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3Bif%20(textField%20%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bamp%3B%20!textField.val().trim()%20%7B%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3Bresult%20%3D%20false%3B%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%2F%2FWrite%20a%20message%20indicating%20to%20the%20user%20that%20the%20field%20is%20empty%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3BWriteErrorMessage(textField%2C%20%22You%20ccan''t%20leave%20this%20blank.%22)%3B%20%20%20%20%20%20%20%20%20%2F%2F%20Intentionally%20made%20double%20c%20in%20ccan't%20to%20see%20if%20this%20message%20is%20coming%20from%20our%20code%20and%20not%20the%20system%20code.%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%7D%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%2F%2FSelect%20the%20textarea%20of%20a%20multi-line%20text%20field%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3Bvar%20multiLineTextField%20%3D%20GetFieldByDisplayName(%22Example%20Multi%20Line%20Text%20Field%22)%3B%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3Breturn%20result%3B%20%0A%7D%20%0A%20%0A%2F%2FAppend%20an%20error%20message%20to%20a%20field%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%20%20%0Afunction%20WriteErrorMessage(inputElement%2C%20message)%7B%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3Bvar%20errorMessageMarkup%20%3D%20'%26amp%3Bamp%3Bamp%3Bamp%3Blt%3Bspan%20class%3D%22errorMessage%20ms-formvalidation%20ms-csrformvalidation%22%26amp%3Bamp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Bamp%3Blt%3Bspan%20role%3D%22alert%22%26amp%3Bamp%3Bamp%3Bamp%3Bgt%3B'%20%2B%20message%20%2B%20'%26amp%3Bamp%3Bamp%3Bamp%3Blt%3Bbr%26amp%3Bamp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Bamp%3Blt%3B%2Fspan%26amp%3Bamp%3Bamp%3Bamp%3Bgt%3B'%3B%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%24(inputElement).parent().append(errorMessageMarkup)%3B%20%0A%7D%20%0A%20%0A%2F%2FGets%20a%20jQuery%20object%20that%20represents%20a%20field%20element%20%0Afunction%20GetFieldByDisplayName(fieldName)%7B%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3Bvar%20field%20%3D%20%24('input%5Btitle%3D%22'%20%2B%20fieldName%20%2B%20'%22%5D%2C%20%5Btitle%3D%22'%20%2B%20fieldName%20%2B%20'%20Required%20Field%22%5D')%3B%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3Bif%20(!field)%7B%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3Bfield%20%3D%20%24('textarea%5Btitle%3D%22'%20%2B%20fieldName%20%2B%20'%22%5D%2C%20%5Btitle%3D%22'%20%2B%20fieldName%20%2B%20'%20Required%20Field%22%5D')%3B%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%7D%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Bamp%3Bnbsp%3Breturn%20field%3B%20%0A%7D%20%0A%26amp%3Bamp%3Bamp%3Bamp%3Blt%3B%2Fscript%26amp%3Bamp%3Bamp%3Bamp%3Bgt%3B%0A%26amp%3Bamp%3Bamp%3Bamp%3Blt%3B%2Fspan%26amp%3Bamp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Blt%3B%2FPRE%26amp%3Bamp%3Bamp%3Bgt%3B%0A%26amp%3Bamp%3Bamp%3Blt%3BP%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Blt%3B%2FP%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Blt%3B%2Flingo-body%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Blt%3Blingo-sub%20id%3D%22lingo-sub-147069%22%20slang%3D%22en-US%22%26amp%3Bamp%3Bamp%3Bgt%3BRe%3A%20Content%20Script%20Editor%20-%20Javascript%20Snippet%26amp%3Bamp%3Bamp%3Blt%3B%2Flingo-sub%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Blt%3Blingo-body%20id%3D%22lingo-body-147069%22%20slang%3D%22en-US%22%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Blt%3BP%26amp%3Bamp%3Bamp%3Bgt%3BThanks%20Juan.%20I%20think%20Microsoft%20is%20trying%20to%20avoid%20adding%20custom%20Javascript%20for%20the%20security%20reasons%20and%20instead%20providing%20the%20limited%20controls%20(to%20start%20with)%20by%20allowing%20customizing%20using%20the%20%26amp%3Bamp%3Bamp%3Bamp%3Bquot%3BPowerApps%26amp%3Bamp%3Bamp%3Bamp%3Bquot%3B.%20But%20there%20also%20we%20can%20add%20custom%20conditions%20and%20actions%20in%20native%20JavaScript.%20Anyways%2C%20I%20will%20give%20up%20and%20take%20a%20back%20seat%20at%20this%20point%20owing%20to%20the%20fact%20of%20me%20not%20knowing%26amp%3Bamp%3Bamp%3Bnbsp%3Bthe%26amp%3Bamp%3Bamp%3Bnbsp%3Bweb%20technologies%20and%20respective%20security%20implications%20etc.%26amp%3Bamp%3Bamp%3Blt%3B%2FP%26amp%3Bamp%3Bamp%3Bgt%3B%0A%26amp%3Bamp%3Bamp%3Blt%3BP%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Blt%3B%2FP%26amp%3Bamp%3Bamp%3Bgt%3B%0A%26amp%3Bamp%3Bamp%3Blt%3BP%26amp%3Bamp%3Bamp%3Bgt%3BBut%20I%20wish%20I%20knew%20any%20my%20snippet%20is%20not%20working%20before%20I%20give%20up.%26amp%3Bamp%3Bamp%3Blt%3B%2FP%26amp%3Bamp%3Bamp%3Bgt%3B%0A%26amp%3Bamp%3Bamp%3Blt%3BP%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Blt%3B%2FP%26amp%3Bamp%3Bamp%3Bgt%3B%0A%26amp%3Bamp%3Bamp%3Blt%3BP%26amp%3Bamp%3Bamp%3Bgt%3BAlso%20when%20I%20created%20a%20team%20site%20in%20Office-365%20and%20then%20created%20a%20list%20under%20it%2C%20and%20assigned%20this%20list%20the%20%26amp%3Bamp%3Bamp%3Bamp%3Bquot%3Bmodern%20experience%26amp%3Bamp%3Bamp%3Bamp%3Bquot%3B.%20Now%20when%20I%20go%20to%20list%20it%20shows%20in%20modern%20view%20showing%20the%20top%20navigation%20bar%20with%20a%20down%20arrow%20etc%2C%20but%20when%20I%20go%20back%20to%20the%20team%20site%20landing%20page%20it%20switches%20the%20top%20nagivation%20bar.%20Is%20there%20a%20way%20I%20could%20have%20a%20consistent%20%26amp%3Bamp%3Bamp%3Bamp%3Bquot%3Bmodern%20experience%26amp%3Bamp%3Bamp%3Bamp%3Bquot%3B%20within%20list%20and%20outside%20list%20(i.e.%20main%20page)%20%3F%26amp%3Bamp%3Bamp%3Blt%3B%2FP%26amp%3Bamp%3Bamp%3Bgt%3B%0A%26amp%3Bamp%3Bamp%3Blt%3BP%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Blt%3B%2FP%26amp%3Bamp%3Bamp%3Bgt%3B%0A%26amp%3Bamp%3Bamp%3Blt%3BP%26amp%3Bamp%3Bamp%3Bgt%3BThanks%20a%20lot.%26amp%3Bamp%3Bamp%3Blt%3B%2FP%26amp%3Bamp%3Bamp%3Bgt%3B%0A%26amp%3Bamp%3Bamp%3Blt%3BP%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Blt%3B%2FP%26amp%3Bamp%3Bamp%3Bgt%3B%0A%26amp%3Bamp%3Bamp%3Blt%3BP%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Blt%3B%2FP%26amp%3Bamp%3Bamp%3Bgt%3B%0A%26amp%3Bamp%3Bamp%3Blt%3BP%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Blt%3B%2FP%26amp%3Bamp%3Bamp%3Bgt%3B%0A%26amp%3Bamp%3Bamp%3Blt%3BP%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Blt%3B%2FP%26amp%3Bamp%3Bamp%3Bgt%3B%0A%26amp%3Bamp%3Bamp%3Blt%3BP%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Blt%3B%2FP%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Blt%3B%2Flingo-body%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Blt%3Blingo-sub%20id%3D%22lingo-sub-147046%22%20slang%3D%22en-US%22%26amp%3Bamp%3Bamp%3Bgt%3BRe%3A%20Content%20Script%20Editor%20-%20Javascript%20Snippet%26amp%3Bamp%3Bamp%3Blt%3B%2Flingo-sub%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Blt%3Blingo-body%20id%3D%22lingo-body-147046%22%20slang%3D%22en-US%22%26amp%3Bamp%3Bamp%3Bgt%3BWell%2C%20I%20would%20say%20that%20depending%20on%20the%20list%20experience%20(classic%20or%20modern)%20you%20have%20to%20use%20different%20techniques...for%20modern%20UI%20the%20only%20technique%20you%20have%20today%20to%20apply%20customizations%20to%20lists%20is%20by%20means%20of%20SPFx%20Extensions%26amp%3Bamp%3Bamp%3Blt%3B%2Flingo-body%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Blt%3Blingo-sub%20id%3D%22lingo-sub-147040%22%20slang%3D%22en-US%22%26amp%3Bamp%3Bamp%3Bgt%3BRe%3A%20Content%20Script%20Editor%20-%20Javascript%20Snippet%26amp%3Bamp%3Bamp%3Blt%3B%2Flingo-sub%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Blt%3Blingo-body%20id%3D%22lingo-body-147040%22%20slang%3D%22en-US%22%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Blt%3BP%26amp%3Bamp%3Bamp%3Bgt%3BThanks%20Juan.%20Idea%20was%20to%20use%20JSLINK%20eventually%20after%20I%20have%20tested%20my%20code%2C%20since%20it%20didn%26amp%3Bamp%3Bamp%3Bamp%3B%2339%3Bt%20work%26amp%3Bamp%3Bamp%3Bnbsp%3Bwith%20snippet%20I%20assume%20it%20wouldn%26amp%3Bamp%3Bamp%3Bamp%3B%2339%3Bt%20with%20JSLINK%20as%20well.%26amp%3Bamp%3Bamp%3Blt%3B%2FP%26amp%3Bamp%3Bamp%3Bgt%3B%0A%26amp%3Bamp%3Bamp%3Blt%3BP%26amp%3Bamp%3Bamp%3Bgt%3BBut%20even%20using%26amp%3Bamp%3Bamp%3Bnbsp%3BJSLINK%2C%20if%20it%26amp%3Bamp%3Bamp%3Bamp%3B%2339%3Bs%20not%20going%20to%20work%20in%20modern%20and%20classic%20sure%20will%20go%20out%20of%20support%20at%20some%20point%2C%20so%20either%20way%20I%20am%20setting%20myself%20up%20for%20failure%20in%20future.%26amp%3Bamp%3Bamp%3Blt%3B%2FP%26amp%3Bamp%3Bamp%3Bgt%3B%0A%26amp%3Bamp%3Bamp%3Blt%3BP%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Blt%3B%2FP%26amp%3Bamp%3Bamp%3Bgt%3B%0A%26amp%3Bamp%3Bamp%3Blt%3BP%26amp%3Bamp%3Bamp%3Bgt%3BSo%20this%20is%20another%26amp%3Bamp%3Bamp%3Bnbsp%3Bfunction%20which%20Microsoft%20is%20going%20away%20with%20in%20Office-365%3F%26amp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Blt%3B%2FP%26amp%3Bamp%3Bamp%3Bgt%3B%0A%26amp%3Bamp%3Bamp%3Blt%3BP%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Blt%3B%2FP%26amp%3Bamp%3Bamp%3Bgt%3B%0A%26amp%3Bamp%3Bamp%3Blt%3BP%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Blt%3B%2FP%26amp%3Bamp%3Bamp%3Bgt%3B%0A%26amp%3Bamp%3Bamp%3Blt%3BP%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Bnbsp%3B%26amp%3Bamp%3Bamp%3Blt%3B%2FP%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Blt%3B%2Flingo-body%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Blt%3Blingo-sub%20id%3D%22lingo-sub-146997%22%20slang%3D%22en-US%22%26amp%3Bamp%3Bamp%3Bgt%3BRe%3A%20Content%20Script%20Editor%20-%20Javascript%20Snippet%26amp%3Bamp%3Bamp%3Blt%3B%2Flingo-sub%26amp%3Bamp%3Bamp%3Bgt%3B%26amp%3Bamp%3Bamp%3Blt%3Blingo-body%20id%3D%22lingo-body-146997%22%20slang%3D%22en-US%22%26amp%3Bamp%3Bamp%3Bgt%3BSince%20you%20are%20on%20the%20classic%20view%20of%20a%20SPO%20list%3A%20why%20not%20using%20JSLINK%20instead%3F%20Also%20bear%20in%20mind%20that%20both%20options%20will%20not%20work%20in%20the%20modern%20UI%26amp%3Bamp%3Bamp%3Blt%3B%2Flingo-body%26amp%3Bamp%3Bamp%3Bgt%3B%3C%2FSCRIPT%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Vivek Jain
Contributor

I am experimenting in an office 365 trial tenant and have a requirement to show a popup message based on the value of a field in my EditForm. I am trying the instructions listed on https://www.dmcinfo.com/latest-thinking/blog/id/9279/sharepoint-form-validation-using-javascript-jqu...

 

It works fine the way it is and shows the error message if the field is left blank etc. But If I add a small code, as underlined below, then the nothing works and not even simple alert messages.

 

Truly appreciate any guidance.

 

<script src="//code.jquery.com/jquery-latest.min.js"></script>	
<script>	
	function PreSaveItem() {
	    a: ;return "function" == typeof PreSaveAction ? PreSaveAction() : true
	}
</script>	
	
<script>	
//When the user clicks 'Save', SharePoint will run this function	
function PreSaveAction(){	
    //Returning true will cause the form to be submitted, false will prevent form submission	
    var result = true;	
    alert("Test");     	
    //Clear out existing error messages	
    $('.errorMessage').remove();	
     	
    //Select the input of a text field	
    var textField = GetFieldByDisplayName("Title");	
    var column1Field = GetFieldByDisplayName("Column 1");	
    alert (textField.val().trim());

    If !(textField.val().trim()) {
       alert(textField.val().trim())
       } else {
      alert("Else Part")
     };
    
    //Check if the input is empty	
    if (textField && !textField.val().trim() {	
        result = false;	
        //Write a message indicating to the user that the field is empty	
        WriteErrorMessage(textField, "You ccan''t leave this blank.");         // Intentionally made double c in ccan't to see if this message is coming from our code and not the system code.	
    }	
     	
    //Select the textarea of a multi-line text field	
    var multiLineTextField = GetFieldByDisplayName("Example Multi Line Text Field");	
 	
    return result;	
}	
	
//Append an error message to a field       	
function WriteErrorMessage(inputElement, message){	
    var errorMessageMarkup = '<span class="errorMessage ms-formvalidation ms-csrformvalidation"><span role="alert">' + message + '<br></span>';	
    $(inputElement).parent().append(errorMessageMarkup);	
}	
	
//Gets a jQuery object that represents a field element	
function GetFieldByDisplayName(fieldName){	
    var field = $('input[title="' + fieldName + '"], [title="' + fieldName + ' Required Field"]');	
    if (!field){	
        field = $('textarea[title="' + fieldName + '"], [title="' + fieldName + ' Required Field"]');	
    }	
    return field;	
}	
</script>
</span>

 

4 Replies
Since you are on the classic view of a SPO list: why not using JSLINK instead? Also bear in mind that both options will not work in the modern UI

Thanks Juan. Idea was to use JSLINK eventually after I have tested my code, since it didn't work with snippet I assume it wouldn't with JSLINK as well.

But even using JSLINK, if it's not going to work in modern and classic sure will go out of support at some point, so either way I am setting myself up for failure in future.

 

So this is another function which Microsoft is going away with in Office-365? 

 

 

 

Well, I would say that depending on the list experience (classic or modern) you have to use different techniques...for modern UI the only technique you have today to apply customizations to lists is by means of SPFx Extensions

Thanks Juan. I think Microsoft is trying to avoid adding custom Javascript for the security reasons and instead providing the limited controls (to start with) by allowing customizing using the "PowerApps". But there also we can add custom conditions and actions in native JavaScript. Anyways, I will give up and take a back seat at this point owing to the fact of me not knowing the web technologies and respective security implications etc.

 

But I wish I knew any my snippet is not working before I give up.

 

Also when I created a team site in Office-365 and then created a list under it, and assigned this list the "modern experience". Now when I go to list it shows in modern view showing the top navigation bar with a down arrow etc, but when I go back to the team site landing page it switches the top nagivation bar. Is there a way I could have a consistent "modern experience" within list and outside list (i.e. main page) ?

 

Thanks a lot.

 

 

 

 

 

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
35 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
9 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
29 Replies