Reputation: 39
I am teaching myself jQuery for flexibility in the work SharePoint environment. I have added this file to the proper destination within SharePoint (and everything seems to be working), but I am still showing some weird highlighting in Sublime Text 3.
Attached is an image of the code in ST3:
Is my syntax correct on source #2? I really do not want to miss anything, though this is quite a small amount of code (forgive me for syntax within the post as I am still getting the hang of it)
<script src = "https://mysite/teams/spe/Style%20Library/tts/jquery-3.3.1.min.js"></script>
<script src = "https://mysite/teams/spe/Style%20Library/tts/sputility.js" > < /script>
<script>
// wait for the window to load
$(document).ready(function() {
// Get a single select dropdown field
var ticketType = SPUtility.GetSPField('Ticket Type');
// create a function to show or hide Priority based on Project's value
var showOrHideField = function() {
var ticketTypeValue = ticketType.GetValue();
// Hide the Priority field if the selected
}
value is Project
if (ticketTypeValue === 'Project') {
SPUtility.HideSPField('Priority');
} else {
SPUtility.ShowSPField('Priority');
};
// run at startup (for edit form)
showOrHideField();
// make sure if the user changes the value we handle it
$(ticketType.Dropdown).on('change', showOrHideField);
//hide Category field from NewForm
SPUtility.HideSPField('Category')
//hide issue status field from NewForm
SPUtility.HideSPField('Issue Status')
//hide comments field from NewForm
SPUtility.HideSPField('Comments')
});
</script>
Upvotes: 2
Views: 496
Reputation: 16311
Assuming you're talking about the pink syntax highlighting, your script URLs in line 1
and line 2
has a literal space and since URLs can't have literal spaces, it is converted to its ASCII code i.e. %20
.
Just replace the %20
with +
and it should remove the syntax error highlighting.
Since URLs often contain characters outside the ASCII set, the URL has to be converted into a valid ASCII format. URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits. URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign or with %20.
Via - URL Encode
If you have access to the website's files and folders, I would recommend checking if the folder Style%20Library
has a folder name of Style Library
or not and if that is the case, rename it to StyleLibrary
and remove the %20 from your script urls.
And assuming you're talking about the script tags syntax color highlighting, well if you change the syntax highlight settings for Sublime Text 3 to HTML, the weird highlight disappears.
It will obviously look weird in js because a js file shouldn't have <script</script>
tags nor the script links in line 1 and line 2 in the first place and you should remove them from your js file.
tldr: Change the syntax highlight settings to HTML in View > Syntax > HTML if this is an html file ior remove the script tags and script links if this is a JS file. Also, avoid literal spaces in folder names and use camelCase writing if you really have to have word distinctions in folder names.
Upvotes: 1
Reputation: 775
You have invalid javascript as well, looks like you were going for this
var showOrHideField = function() {
var ticketTypeValue = ticketType.GetValue();
// Hide the Priority field if the selected value is Project
if (ticketTypeValue === 'Project') {
SPUtility.HideSPField('Priority');
} else {
SPUtility.ShowSPField('Priority');
}
}
Upvotes: 0