2

I am using HillBillyForm.js by Mark Rackley to customise a couple of forms:

<script src="//code.jquery.com/jquery-1.10.1.min.js"></script>

<script type="text/javascript">
    $(document).ready(function() {
        //loop through all the spans in the custom layout        
        $("span.hillbillyForm").each(function()
        {
            //get the display name from the custom layout
            displayName = $(this).attr("data-displayName");

            displayName  = displayName.replace(/&(?!amp;)/g,'&amp;');
            elem = $(this);

            //find the corresponding field from the default form and move it
            //into the custom layout
            $("table.ms-formtable td").each(function(){
                if (this.innerHTML.indexOf('FieldName="'+displayName+'"') != -1){
                    $(this).contents().appendTo(elem);                  
                }                 
            }); 
        });
    });
</script>

Where I have saved the above in hillbillyForm.js

This is working great, but I recently came across a problem where some of our users who do not have internet access need to use these forms.

The issue is that that HillBillyForm requires JQuery to work, but I can't use the CDN due to lack of internet connectivity.

My solution is to include the raw JQuery code in HillBillyForm.js, and this does work. However, I feel it would be a lot neater if I could add this as a separate file, say jquery-1.10.1.js into my SiteAssets and call it from HillBillyform.js.

I have tried adding the following lines to HillBillyForm.js after creating jquery-1.10.1.js in SiteAssets:

<script src="../../SiteAssets/jquery-1.10.1.js"></script>

<script src="/SiteAssets/jquery-1.10.1.js"></script>

<script src="SiteAssets/jquery-1.10.1.js"></script>

<script type="text/javascript" src="http://server/Knowledge/RISK/Expert/SiteAssets/jquery-1.10.1.js"></script>

<script type="text/javascript" src="https://server/Knowledge/RISK/Expert/SiteAssets/jquery-1.10.1.js"></script>

However none of these appear to work (I get a null-reference error in the same place as when there is no Jquery at all).

So my question is, how can I call a SiteAsset file from another file in SiteAssets?

2

Consider that

  • The Parent Site URL is : http://SPQassas/
  • The SubSite URL is : http://SPQassas/TeamSite

If your script file has been located at site asset library of the same subsite http://SPQassas/TeamSite , use the following

<script src="../SiteAssets/cookies.js" type="text/javascript"></script>

If your script file has been located at site asset library of the parent site http://SPQassas/ and you need to use it in your subsite http://SPQassas/TeamSite, use the following

<script src="../../SiteAssets/cookies.js" type="text/javascript">

If it still not working , so the issue is not related to the path it's related to the JS file itself, try to use another JS file with the above relative path guides and check if it's worked or not.

1
  • I have tried these suggestions without any success. The only way I can get it to work is if I directly past the raw JQuery code into hillbillyForm.js inside some <script> tags. I don't see how this can be caused by the JS file if the code works when pasting it directly into hillbillyForm.js
    – Bassie
    Sep 5 '16 at 13:29
2

This works for me using the Hillbilly tabs (in a site collection). If you are in a subsite, use the full URL.

<script type="text/javascript" src="../SiteAssets/jquery-1.11.1.min.js"></script>

It should not matter that both the txt file and the jquery is in the same library.

For a subsite, it can look like this. It's just the full URL to the file location.

<script type="text/javascript" src="https://dev.contoso.sharepoint.com/contosoSubsite/SiteAssets/jquery-1.11.2.min.js"></script>
3
  • This code has the same effect as my other attempts. Could you please let me know how I can find the "full URL" for SiteAssets? (I think I may be in a subsite)
    – Bassie
    Sep 5 '16 at 11:46
  • Updated answer. Sep 5 '16 at 11:50
  • Thanks Christoffer, I have tried including the full literal path but without any luck (this is using an account which will always have internet access). I included the new attempts in my question but will keep trying variations ...
    – Bassie
    Sep 5 '16 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.