Git Product home page Git Product logo

sputility's Introduction

This project is no longer being maintained. The final release of SPUtility.js is 0.14.2.

SPUtility.js

A JavaScript library used to make modifications to SharePoint's list forms (NewForm.aspx and EditForm.aspx in a survey, custom list or library). SPUtility.js works with SharePoint 2007, 2010, and 2013.

This library depends on jQuery (tested with v1.9.0+). I recommend using version 1.x of jQuery in order to support older versions of IE.

Usage

Upload jQuery and SPUtility into a Document Library in your SharePoint site.

Edit the SharePoint form you wish to modify and add a Content Editor Web Part with the following script inside of it:

<script src="/site/Files/jquery.js"></script>
<script src="/site/Files/sputility.min.js"></script>
<script>
$(window).load(function () {
   // TODO: Your scripts go here!

   // EXAMPLE: Set the value of the Title field to Hello world!
   SPUtility.GetSPField('Title').SetValue('Hello world!');
});
</script>

Step by step install instructions are located here: https://github.com/kitmenke/sputility/blob/master/WikiFiles/docs/Installation.md

Documentation

Documentation was migrated from Codeplex to Markdown files in this repo: https://github.com/kitmenke/sputility/blob/master/WikiFiles/docs/

Examples

// Set the value of the Title field to Hello world!
SPUtility.GetSPField('Title').SetValue('Hello world!');

// Get the value of the Title field
SPUtility.GetSPField('Title').GetValue(); // returns "Hello world!"

// Make the Title field read only
SPUtility.GetSPField('Title').MakeReadOnly();

// Hide the entire row from view
SPUtility.GetSPField('Title').Hide();

// You can also set a variable to the returned field
var fTitle = SPUtility.GetSPField('Title');
fTitle.SetValue('Using my variable!');

For Developers Getting Started

SPUtility.js uses Grunt to run tests, check code syntax, and compress/minify/uglify files for use in production.

Install node.js and npm.

Install grunt:

npm install -g grunt-cli
npm install grunt

Install git and clone SPUtility.js:

git clone https://github.com/kitmenke/sputility.git

Install SPUtility.js dependencies:

cd sputility
npm install

If everything went ok, you should be able to run grunt in the sputility directory.

Executing grunt will run all of the tasks (jshint, qunit, uglify). Or, you can run them individually, for example: grunt jshint will run just the unit tests.

Contributing

This project is no longer maintained so contributions are no longer accepted.

Release History

https://github.com/kitmenke/sputility/blob/master/WikiFiles/docs/Changelog.md

License

MIT

sputility's People

Contributors

kitmenke avatar rawkbob avatar szykov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sputility's Issues

IsRequired

Can anyone please assist me on how IsRequired is implemented because it doesn't seem to work on my side.

People fields (SPUserField) set value and get value not working

Hello,

I'd like to submit 2 bug fixings and 2 new features.

  1. Bug: SPUserField, it misses the "#" part (around line 1286)
this.upLevelDiv = $("#" + this.spanUserField.id + '_upLevelDiv');
this.textareaDownLevelTextBox = $("#" + this.spanUserField.id + '_downlevelTextBox');
this.linkCheckNames = $("#" +this.spanUserField.id + '_checkNames');
this.txtHiddenSpanData = $("#" +this.spanUserField.id + '_hiddenSpanData');

GetValue() (line 1291)

this.GetValue = function () {
     var peopleSpans = this.upLevelDiv.find('span.ms-entity-resolved');
     if (peopleSpans.length > 0) {
        return arrayToSemicolonList(peopleSpans);
     }
     return '';
};
  1. Feature: add Description to SPField (line 377)
    This expose the Description of a field as a text element.
this.Description = (function(ctls) { var c = ctls.childNodes[ctls.childNodes.length-1]; return (c.nodeType!=3 || $(c).text().replace(/\s/g,'').length == 0)? null : c; })(fieldParams.controlsCell);
  1. Feature: registering "change" event in SPUserField (line 1334, at the bottom of SPUserField class)
var currentValue = null;
this.OnChange = function(fn) {
      var handler = getMethodName(fn) + "()";
      $(this.upLevelDiv[0], this.textareaDownLevelTextBox[0]).attr("onvaluesetfrompicker", handler);

      currentValue = this.GetValue();
      this.upLevelDiv.blur($.proxy(function() {
           if (this.GetValue() !== currentValue) {
               currentValue = this.GetValue();
               fn();
           }
      }, this));
};

Usage:

SPUtility.GetSPField("Nominated User").OnChange(requestUser);
function requestUser() {
    var val = SPUtility.GetSPField("Nominated User").GetValue();
    if (!val.length) return;
    alert(val);
}

And this method to get the list of resolved users by loginName/display Name:

this.GetUsers = function() {
    var people = [], peopleSpans = this.upLevelDiv.find('span.ms-entity-resolved');
    if (peopleSpans.length > 0) {
        $(peopleSpans).each(function () {
            var c = this.firstChild;
            people.push({ id: c.getAttribute('key'), title: c.getAttribute('displaytext') });
        });
    }
    return people;
};

Of course, feel free to rename the methods as you want.

Tested on IE 8 & Chrome

SPUtility should allow retrieving fields by internal column name

Allow retrieving a fields by internal column name.

Currently lazyLoadSPFields works quickly by only finding the display names. To index internal column names, each field would have to be parsed which can cause performance issues with large lists.

Considering adding a new method or an overload of GetSPField to allow this.

SPUtility.GetSPField return 50 instead of 50.000

SPUtility.GetSPField return 50 instead of 50.000

Before:
Title 50.000 (fifty thousand in the European numbering system)

var myField = SPUtility.GetSPField('Title');
myField.MakeReadOnly();

After:
Title 50 (fifty)

I use SP2007

Can you fix the problem?
Thanks

Stefano

How i can make a MakeReadOnly() field Editable again ?

I am facing this problem when using SPUtility.js inside my SP 2013 on-premises, now i want to do the following inside my sharepoint 2013 list forms:-

  1. Set a Choice field as ReadOnly.
  2. then chnage the value of the ReadOnly Choice field using SPUtility or pure JavaScript.

now to make my Choice field ReadOnly i use the following SPUtility method:-

SPUtility.GetSPFieldByInternalName('OrderStatus').MakeReadOnly();

but when i tired to change the value of the list after making it ReadOnly, as follow:-

SPUtility.GetSPFieldByInternalName('OrderStatus').SetValue("In Progress");

OR using pure javascript appraoch as follow:-

$('[id^="OrderStatus"]').val("In Progress");

i was unable to change the status value? so can anyone adivce how i can handle this problem? so i can change the value of a ReadOnly list?
second point, is there a way i can temporary remove the MakeReadOnly() effect on the field? if this is possible , then i can remove the ReadOnly effect on the Choice field, then set its value, then make it as ReadOnly again ?
Thanks

SPLookupMultiField SetValue timing issue with Firefox

Multi-select lookup fields use buttons to move selected options between the two select boxes.

In Firefox, calling SetValue multiple times in a row can result in a value not being set.

This issue does not seem to affect Chrome.
TODO: test IE

SPUtility should allow setting the date or time portions of DateTime fields individually

Date time fields contain multiple controls: a calendar control (textbox) for the date, a dropdown for hour, and a dropdown for minute.

The current API supports setting just date and date plus time. It does not support setting Time only.

API should support the ability to set just the time and force the user to fill out the date.
var field = SPUtility.GetSPField('Date and Time');
field.SetTime(8, 30);
field.SetTime('6 PM', '00');

Not working at all

I am trying to get SPutility to work in Sharepoint online. I could not get any scripts to work in neither script editor nor content editor web parts. I don't have access to custom forms advanced mode editing (yet - i hope i will get it soon from the admin). I managed to find a workaround by using Form HTML webpart and editing its source code and putting my script there. jQuery works and gives me the test alert, but nothing happens when i try to get an alert from SPUtility. ( I also tried using some functions on the form like autocomplete but no luck there as well. Here's the code:

<script language="javascript" type="text/javascript" src="/SiteAssets/jquery-3.2.1.js"></script>
<script language="javascript" type="text/javascript" src="/SiteAssets/jquery.SPServices.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
 alert("jQuery");
alert($().SPServices.SPGetCurrentSite());
});
</script>

Correctly detect DispForm for Document Libraries

The code below can't detect DispForm for document libraries:

if (formBodies.length > 0 && $(formBodies[0]).children().length === 0) {
   _isDispForm = true;
 }

Need to find better alternative, maybe look at the form's buttons?

Getting a LookupField on the DispForm gives exception

Reported by GenericCodeMonkey:

When I want to get a LookupField in the DisplayForm i get the Exception:
throw "Unable to get input elements for " + this.Name;
from SPAutocompleteLookupField(fieldParams, elemInputs)
because elemInputs is passed with a length of 0 from getSPFieldFromType(spFieldParams)
at case 'SPFieldLookup'

My workaround is to just not throw the exception:

function SPAutocompleteLookupField(fieldParams, elemInputs) {
 SPField.call(this, fieldParams);
 if (this.Controls === null) {
    return;
 }

 if (1 === elemInputs.length) {
    // autocomplete lookup
    this.Textbox = $(elemInputs[0]);
    this.HiddenTextbox = $('input[id="' + this.Textbox.attr('optHid') + '"]');
 } else {
  return;//MyFix
    throw "Unable to get input elements for " + this.Name;
 }
}

SPUtility.GetSPField('Title').SetValue('Hello world!');

Добрый день, Ваш пример не работает в SPS Russian language

SPUtility.GetSPField('Кем проверен кандидат').SetValue('Hello world!');
sputility.min.js:10 Uncaught Unable to get a SPField named Кем проверен кандидат
$.GetSPField @ sputility.min.js:10

Пробовал StaticName указать:
SPUtility.GetSPField('FirstEdit').SetValue('Hello world!');
sputility.min.js:10 Uncaught Unable to get a SPField named FirstEdit

NPM

Hi,

please add your package to npm public repository. It would help all developers which use npm for their package repository a lot. In my company we are currently shifting from bower to npm

Thank you,
Viktor

Unable to Hide fields on DispForm

Attempting to hide the Title field on DispForm results in this error:

Uncaught Error creating field named Title: Unable to retrieve the input control for Title

Unable to get value of Content Type field on EditForm

Steps to repro:

  1. Create a custom list
  2. Turn on management of content types in advanced settings
  3. Add multiple content types to the list
  4. Create an item in the list
  5. Edit the item

On the EditForm, a Content Type field is now displayed at the top. Expected behavior would be to get the value of this field like: SPUtility.GetSPField('Content Type').GetValue();

Issue is: SPUtility is unable to determine the type of the Content Type field and returns null.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.