├── .gitignore
├── .jshintrc
├── CONTRIBUTING.md
├── Gruntfile.js
├── LICENSE-MIT
├── README.md
├── WikiFiles
├── docs
│ ├── Changelog.md
│ ├── Choice fields.md
│ ├── Common SPField functions.md
│ ├── Content Type fields.md
│ ├── Date fields.md
│ ├── Documentation.html
│ ├── Home.html
│ ├── Home_sputility_assignedto.png
│ ├── Home_sputility_assignedto_readonly.png
│ ├── Home_sputility_hide_after.png
│ ├── Home_sputility_hide_before.png
│ ├── Home_sputility_status.png
│ ├── Home_sputility_status_readonly.png
│ ├── Home_sputility_title.png
│ ├── Home_sputility_title_readonly.png
│ ├── Installation.md
│ ├── Installation_2013-add-content-editor.png
│ ├── Installation_2013-content-link.png
│ ├── Installation_2013-form-web-parts.png
│ ├── Installation_2013-title-hello-world.png
│ ├── Installation_sp2010-default-edit-form.PNG
│ ├── Lookup fields.md
│ ├── People fields.md
│ ├── Text fields.md
│ ├── Troubleshooting.md
│ ├── Troubleshooting_sputility-chrome-console-bad.png
│ ├── Troubleshooting_sputility-chrome-console.png
│ ├── URL Fields.md
│ └── Yes_No fields.md
└── raw
│ ├── Changelog.codeplexwiki
│ ├── Choice fields.codeplexwiki
│ ├── Common SPField functions.codeplexwiki
│ ├── Content Type fields.codeplexwiki
│ ├── Date fields.codeplexwiki
│ ├── Documentation.html
│ ├── Home.html
│ ├── Home_sputility_assignedto.png
│ ├── Home_sputility_assignedto_readonly.png
│ ├── Home_sputility_hide_after.png
│ ├── Home_sputility_hide_before.png
│ ├── Home_sputility_status.png
│ ├── Home_sputility_status_readonly.png
│ ├── Home_sputility_title.png
│ ├── Home_sputility_title_readonly.png
│ ├── Installation.codeplexwiki
│ ├── Installation_2013-add-content-editor.png
│ ├── Installation_2013-content-link.png
│ ├── Installation_2013-form-web-parts.png
│ ├── Installation_2013-title-hello-world.png
│ ├── Installation_sp2010-default-edit-form.PNG
│ ├── Lookup fields.codeplexwiki
│ ├── People fields.codeplexwiki
│ ├── Text fields.codeplexwiki
│ ├── Troubleshooting.codeplexwiki
│ ├── Troubleshooting_sputility-chrome-console-bad.png
│ ├── Troubleshooting_sputility-chrome-console.png
│ ├── URL Fields.codeplexwiki
│ └── Yes_No fields.codeplexwiki
├── bower.json
├── dist
├── sputility.js
└── sputility.min.js
├── examples
├── contenttype.html
├── dependentfields.html
├── dispform.html
├── dropdownchange.html
├── gettingstarted.html
├── helloworld.html
├── showhidedependentfield.html
├── sputilitytree.js
└── text-depends-on-checkbox.html
├── libs
├── jquery-loader.js
├── jquery
│ └── jquery.js
└── qunit
│ ├── qunit.css
│ └── qunit.js
├── package.json
├── sputility.json
├── src
├── .jshintrc
└── sputility.js
└── test
├── .jshintrc
├── TODO_test_list_no_comments.html
├── img
├── blank.gif
└── calendar.gif
├── integration_test_2007.js
├── integration_test_2013.html
├── integration_test_2013.js
├── test_boolean.html
├── test_boolean.js
├── test_dispform.js
├── test_doclib_dispform_2013.html
├── test_doclib_dispform_2013.js
├── test_field_properties.js
├── test_list.html
├── test_list.js
├── test_list_dispform.html
├── test_list_dispform.js
├── test_list_eu.html
├── test_list_eu.js
├── test_list_extra_elems.html
├── test_sputility.js
├── test_survey_2013.html
├── test_survey_2013.js
├── test_survey_dispform_2013.html
└── test_survey_dispform_2013.js
/.gitignore:
--------------------------------------------------------------------------------
1 | /node_modules/
2 | /nbproject/private/
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "curly": true,
3 | "eqeqeq": true,
4 | "immed": true,
5 | "latedef": true,
6 | "newcap": true,
7 | "noarg": true,
8 | "sub": true,
9 | "undef": true,
10 | "unused": true,
11 | "boss": true,
12 | "eqnull": true,
13 | "node": true
14 | }
15 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | ## Important notes
4 | Please don't edit files in the `dist` subdirectory as they are generated via Grunt. You'll find source code in the `src` subdirectory!
5 |
6 | ### Code style
7 | Regarding code style like indentation and whitespace, **follow the conventions you see used in the source already.**
8 |
9 | ### PhantomJS
10 | While Grunt can run the included unit tests via [PhantomJS](http://phantomjs.org/), this shouldn't be considered a substitute for the real thing. Please be sure to test the `test/*.html` unit test file(s) in _actual_ browsers.
11 |
12 | ## Modifying the code
13 | First, ensure that you have the latest [Node.js](http://nodejs.org/) and [npm](http://npmjs.org/) installed.
14 |
15 | Test that Grunt's CLI is installed by running `grunt --version`. If the command isn't found, run `npm install -g grunt-cli`. For more information about installing Grunt, see the [getting started guide](http://gruntjs.com/getting-started).
16 |
17 | 1. Fork and clone the repo.
18 | 1. Run `npm install` to install all dependencies (including Grunt).
19 | 1. Run `grunt` to grunt this project.
20 |
21 | Assuming that you don't see any red, you're ready to go. Just be sure to run `grunt` after making any changes, to ensure that nothing is broken.
22 |
23 | ## Submitting pull requests
24 |
25 | 1. Create a new branch, please don't work in your `master` branch directly.
26 | 1. Add failing tests for the change you want to make. Run `grunt` to see the tests fail.
27 | 1. Fix stuff.
28 | 1. Run `grunt` to see if the tests pass. Repeat steps 2-4 until done.
29 | 1. Open `test/*.html` unit test file(s) in actual browser to ensure tests pass everywhere.
30 | 1. Update the documentation to reflect any changes.
31 | 1. Push to your fork and submit a pull request.
32 |
--------------------------------------------------------------------------------
/Gruntfile.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = function(grunt) {
4 |
5 | // Project configuration.
6 | grunt.initConfig({
7 | // Metadata.
8 | pkg: grunt.file.readJSON('sputility.json'),
9 | banner: '/*\n' +
10 | ' Name: <%= pkg.title || pkg.name %>\n' +
11 | ' Version: <%= pkg.version %>\n' +
12 | ' Built: <%= grunt.template.today("yyyy-mm-dd") %>\n' +
13 | ' Author: <%= pkg.author.name %>\n' +
14 | ' <%= pkg.homepage %>\n' +
15 | ' Copyright (c) <%= grunt.template.today("yyyy") %>\n' +
16 | ' License: <%= _.pluck(pkg.licenses, "type").join(", ") %>\n' +
17 | '*/\n',
18 | // Task configuration.
19 | clean: {
20 | files: ['dist']
21 | },
22 | concat: {
23 | options: {
24 | banner: '<%= banner %>',
25 | stripBanners: false
26 | },
27 | dist: {
28 | src: ['src/<%= pkg.name %>.js'],
29 | dest: 'dist/<%= pkg.name %>.js'
30 | },
31 | },
32 | uglify: {
33 | options: {
34 | banner: '<%= banner %>'
35 | },
36 | dist: {
37 | src: '<%= concat.dist.dest %>',
38 | dest: 'dist/<%= pkg.name %>.min.js'
39 | },
40 | },
41 | qunit: {
42 | files: [
43 | 'test/test_*.html'
44 | ]
45 | },
46 | jshint: {
47 | gruntfile: {
48 | options: {
49 | jshintrc: '.jshintrc'
50 | },
51 | src: 'Gruntfile.js'
52 | },
53 | src: {
54 | options: {
55 | jshintrc: 'src/.jshintrc'
56 | },
57 | src: ['src/**/*.js']
58 | },
59 | test: {
60 | options: {
61 | jshintrc: 'test/.jshintrc'
62 | },
63 | src: ['test/**/*.js']
64 | },
65 | },
66 | watch: {
67 | gruntfile: {
68 | files: '<%= jshint.gruntfile.src %>',
69 | tasks: ['jshint:gruntfile']
70 | },
71 | src: {
72 | files: '<%= jshint.src.src %>',
73 | tasks: ['jshint:src', 'qunit']
74 | },
75 | test: {
76 | files: '<%= jshint.test.src %>',
77 | tasks: ['jshint:test', 'qunit']
78 | },
79 | },
80 | });
81 |
82 | // These plugins provide necessary tasks.
83 | grunt.loadNpmTasks('grunt-contrib-clean');
84 | grunt.loadNpmTasks('grunt-contrib-concat');
85 | grunt.loadNpmTasks('grunt-contrib-uglify');
86 | grunt.loadNpmTasks('grunt-contrib-qunit');
87 | grunt.loadNpmTasks('grunt-contrib-jshint');
88 | grunt.loadNpmTasks('grunt-contrib-watch');
89 |
90 | // Default task.
91 | grunt.registerTask('default', ['jshint', 'qunit', 'clean', 'concat', 'uglify']);
92 | grunt.registerTask('test', ['jshint', 'qunit']);
93 |
94 | };
95 |
--------------------------------------------------------------------------------
/LICENSE-MIT:
--------------------------------------------------------------------------------
1 | Copyright (c) 2013 Kit Menke
2 |
3 | Permission is hereby granted, free of charge, to any person
4 | obtaining a copy of this software and associated documentation
5 | files (the "Software"), to deal in the Software without
6 | restriction, including without limitation the rights to use,
7 | copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the
9 | Software is furnished to do so, subject to the following
10 | conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 | OTHER DEALINGS IN THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # This project is no longer being maintained. The final release of SPUtility.js is 0.14.2.
2 |
3 | # SPUtility.js
4 |
5 | A JavaScript library used to make modifications to SharePoint's list forms
6 | (NewForm.aspx and EditForm.aspx in a survey, custom list or library).
7 | SPUtility.js works with SharePoint 2007, 2010, and 2013.
8 |
9 | This library depends on jQuery (tested with v1.9.0+). I recommend using
10 | version 1.x of jQuery in order to support older versions of IE.
11 |
12 | ## Usage
13 |
14 | Upload jQuery and SPUtility into a Document Library in your SharePoint site.
15 |
16 | Edit the SharePoint form you wish to modify and add a Content Editor Web Part
17 | with the following script inside of it:
18 |
19 | ```html
20 |
21 |
22 |
30 | ```
31 |
32 | Step by step install instructions are located here: https://github.com/kitmenke/sputility/blob/master/WikiFiles/docs/Installation.md
33 |
34 | ## Documentation
35 |
36 | Documentation was migrated from Codeplex to Markdown files in this repo: https://github.com/kitmenke/sputility/blob/master/WikiFiles/docs/
37 |
38 | ## Examples
39 | ```javascript
40 | // Set the value of the Title field to Hello world!
41 | SPUtility.GetSPField('Title').SetValue('Hello world!');
42 |
43 | // Get the value of the Title field
44 | SPUtility.GetSPField('Title').GetValue(); // returns "Hello world!"
45 |
46 | // Make the Title field read only
47 | SPUtility.GetSPField('Title').MakeReadOnly();
48 |
49 | // Hide the entire row from view
50 | SPUtility.GetSPField('Title').Hide();
51 |
52 | // You can also set a variable to the returned field
53 | var fTitle = SPUtility.GetSPField('Title');
54 | fTitle.SetValue('Using my variable!');
55 | ```
56 |
57 | ## For Developers Getting Started
58 |
59 | SPUtility.js uses [Grunt](http://gruntjs.com/) to run tests, check code syntax, and compress/minify/uglify files for use in production.
60 |
61 | [Install node.js and npm](https://docs.npmjs.com/getting-started/installing-node).
62 |
63 | Install grunt:
64 | ```
65 | npm install -g grunt-cli
66 | npm install grunt
67 | ```
68 | Install git and clone SPUtility.js:
69 | ```
70 | git clone https://github.com/kitmenke/sputility.git
71 | ```
72 | Install SPUtility.js dependencies:
73 | ```
74 | cd sputility
75 | npm install
76 | ```
77 |
78 | If everything went ok, you should be able to run `grunt` in the sputility directory.
79 |
80 | 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.
81 |
82 | ## Contributing
83 | This project is no longer maintained so contributions are no longer accepted.
84 |
85 | ## Release History
86 | https://github.com/kitmenke/sputility/blob/master/WikiFiles/docs/Changelog.md
87 |
88 | ## License
89 | MIT
90 |
--------------------------------------------------------------------------------
/WikiFiles/docs/Changelog.md:
--------------------------------------------------------------------------------
1 | ### Version 0.14.2 (April 19, 2016)
2 | * Corrected version number string in file header
3 |
4 | ### Version 0.14.1 (April 18, 2016)
5 | * BUG: Fix empty Number fields displaying as NaN when in read only mode
6 | * BUG: Fix date and time fields which have no date displaying the time only in read only mode
7 |
8 | ### Version 0.14.0 (March 30, 2016)
9 | * FEATURE: Add ability to configure SPUtility.js with SPUtility.Setup(...)
10 | * FEATURE: Allow customizing Yes/No field (SPBooleanField) string values. (Thank you szykov!)
11 | * FEATURE: Improvement to SPUserField2013 to display links to users instead of just text. (Thank you szykov!)
12 | * FEATURE: Allow getting the hashtable of all fields by internal name using SPUtility.GetSPFieldsInternal() (Thank you ViktorHofer!)
13 | * DEPRECATED: The following functions will be removed in a future release: GetThousandsSeparator, SetThousandsSeparator, GetDecimalSeparator, SetDecimalSeparator, GetDateSeparator, SetDateSeparator, GetTimeFormat, and SetTimeFormat. Use SPUtility.Setup(...) instead!
14 | * BUG: SPUserField2013 read only label should now be updated correctly if the value is changed.
15 | * Huge refactoring of internal field creation. This helps especially for getting fields by their internal column name. (Thank you ViktorHofer!)
16 |
17 | ### Version 0.13.0 (March 22, 2016)
18 | * FEATURE (or bug?): Support for different thousands and decimal separators using SetDecimalSeparator and SetThousandsSeparator (thank you ViktorHofer!)
19 | * FEATURE: Full support for GetValue and SetValue on DispForm for fields which display as text (Text, Number, Date, most Choice fields, Yes/No) via a new class: SPDispFormTextFields. Note:
20 | * BUG: Fix detection of DispForm especially for document libraries.
21 | * BUG: Fix read-only label not updating for SP 2013 people fields (thank you ViktorHofer!)
22 | * Added soooo many unit tests....
23 |
24 | ### Version 0.12.0 (February 28, 2016)
25 | * BREAKING CHANGE: LabelRow and ControlsRow properties no longer return the jquery object but instead return the TR element itself.
26 | * BUG: Fix Survey support in SharePoint 2013
27 | * BUG: Fix MakeReadOnly method on people fields in SharePoint 2013
28 | * FEATURE: Support for GetValue on DispForm via a new special type
29 | * FEATURE: Add InternalName property to all fields (thank you RawkBob!)
30 |
31 | ### Version 0.11.2 (March 10, 2015)
32 | * BUG / FEATURE: Date separator for date/time fields was hard coded to a '/'. Added a new function, SPUtility.SetDateSeparator, which allows the user to change it.
33 | * BUG: SetDescription not working in SharePoint 2007
34 |
35 | ### Version 0.11.1 (February 26, 2015)
36 | * BUG: Issue with getting current SharePoint version breaks the library
37 |
38 | ### Version 0.11.0 (February 23, 2015)
39 | * FEATURE: Add GetDescription and SetDescription to SPField. Allows you to manipulate descriptions for any field type!
40 | * FEATURE: Add SPFieldBusinessData
41 | * BUG: More fixes for SharePoint 2007/2010 SPUserField
42 | Big thanks to Onizet for the contributions! [https://sputility.codeplex.com/discussions/580446](https://sputility.codeplex.com/discussions/580446)
43 |
44 | ### Version 0.10.0 (February 12, 2015)
45 | * FEATURE: Support for 24 hour time format with date and time fields!
46 | * FEATURE: Support for people fields in SharePoint 2013!
47 | * BUG: Fix spacing and padding with 12 hour time formats.
48 | * BUG: Fix selectors in SPUserField (thanks onizet!)
49 | * More examples added!
50 |
51 | ### Version 0.9.4 (November 9, 2014)
52 | * BUG: Yes/No fields should display "Yes" or "No" instead of true or false after calling MakeReadOnly.
53 | * BUG: Yes/No fields - SetValue not working correctly.
54 |
55 | ### Version 0.9.3 (September 29, 2014)
56 | * BUG: Checkbox fields should allow unchecking a field by passing a second boolean parameter set to false.
57 |
58 | ### Version 0.9.2 (July 1, 2014)
59 | * BUG: Should allow getting field names that are one character.
60 |
61 | ### Version 0.9.1 (May 8, 2014)
62 | * FEATURE: Get fields using their internal column name: GetSPFieldByInternalName. See [Common SPField functions](Common-SPField-functions)
63 | * FEATURE: DateTime fields now have two special methods: SetDate and SetTime. This allows you to set (or reset) the date or time individually. Also, both methods now support integer and string values! Also, calling GetValue will consistently return a SPDateTimeFieldValue object with integer properties for year, month, day, hour, and minute. See [Date fields](Date-fields)
64 | * FEATURE/BUG: GetSPField now supports being able to retrieve the Content Type field see [Content Type fields](Content-Type-fields)
65 |
66 | ### Version 0.9.0 (April 2, 2014)
67 | * BUG: Should be able to make mult-select lookup fields read-only (fixes #6).
68 | * Refactored read-only methods to be class-level methods.
69 | * CHANGE: Deprecate Debug mode (throw exceptions instead).
70 | * BUG: Added HideSPField, ShowSPField, and GetSPFields public methods back.
71 | * Refactored how global SPUtility variable is set(again).
72 | * BUG: When a field is read-only, setting the value should update the label
73 | * Added examples
74 |
75 | ### Version 0.8.4 (now with 100% more jQuery!!!) (March 4, 2014)
76 | * Complete re-implementation of SPUtility using jQuery instead of prototype.js.
77 | * QUnit tests implemented for all of the fields
78 | * Ability to clear a date field after it has been set by passing null
79 | * Support for SharePoint 2013
80 |
81 | **Prototype.js version discontinued and superseded by the jQuery version.**
82 |
83 | ### Version 0.8.2 (bug-fix update) (March 9, 2013):
84 | * BUG: Fixed not being able to Hide fields on DispForm.aspx
85 | * BUG: Fixed Large Lookup fields not saving value correctly (thank you lambi_uk!)
86 | * BUG: Fixed not being able to call SetValue for Large Lookup fields when the value contained a space (thank you MarkETolley!)
87 |
88 | ### Version 0.8.1 (bug fix update) (April 23, 2012)
89 | * BUG: Fixed problem with making empty date fields read only
90 | * BUG: Fixed problem where setting the value of a read only field now didn't update the label
91 | * FEATURE: Can now pass a string to a SPDateTimeField to set the date textbox
92 |
93 | ### Version 0.8 (April 26, 2011)
94 | * FEATURE: Support for rich text fields
95 | * FEATURE: Support for choice fields with fill-in values
96 | * BUG: Support for unchecking multi-select checkboxes
97 |
98 | ### Version 0.7 (February 6, 2011)
99 | * FEATURE: New SPLookupMultiField class to support multi-select lookup fields. Also various improvements to allow setting the values using list item ID or the text value for all Lookup fields.
100 | * BUG: Fixed chaining after SetValue for single select lookup fields
101 | * CHANGE: Refactored _makeReadOnly to be a private function
102 |
103 | ### Version 0.6 (January 31, 2011)
104 | * FEATURE: SPUtility now can detect and load supported fields on Survey forms.
105 | * FEATURE: New HideSPField and ShowSPField functions. These functions function the same as SPField.Hide/Show except the entire field won't be initialized. This can be useful on very large forms that only need to show/hide fields (ex: tabs).
106 | * FEATURE: Debug function for troubleshooting: call SPUtility.Debug(true) before your SPUtility code to show alerts (firebug console messages if possible).
107 | * UPDATE: getSPFieldType optimized.
108 | * UPDATE: Fields are now initialized when GetSPField is called (not before).
109 | * BUG: The function 'createSPField' no longer throws an error: problem where if a field had a problem, any fields after would not be detected.
110 | * UPDATE: Updates to SPChoiceField to detect when the field allows for Fill-in values (partial support, currently can set the normal options but not Fill-in values yet)
111 |
112 | ### Version 0.5 (January 8, 2011)
113 | * Bug: SPNumberField GetValue() function now disregards commas
114 | * _Breaking change_: GetSPFields will now return a hashtable instead of the array (see next item)
115 | * GetSPField now loads fields into a hashtable instead of an array (dramatically increases speed for forms with a large number of fields)
116 | * GetSPFieldType now attempts to prevent throwing an error when unable to get the field's type (allows for easier Firebugging).
117 | * New MakeEditable function, will undo MakeReadOnly
118 | * Support for currency fields. MakeReadOnly will display the value with dollar sign, and commas. Uses formatMoney function made by Jonas Raoni Soares Silva.
119 | * Support for single select lookup fields
120 | * Reformatted code to meet higher JSLint standards
121 |
122 | ### Version 0.4 (November 13, 2010)
123 |
124 | * Bug: Unable to update the read only label. Fix allows developer to call MakeReadOnly again to update the label.
125 | * Bug: Getting the value of a number field would sometimes return a string. GetValue now will always return a number.
126 | * GetSPField now will throw a helpful error if the field is not found.
127 | * Support for **plain text** "Multiple lines of text" fields (SPFieldNote). Support for the rich text versions is still a work in progress.
128 | * Support for Yes/No fields. New SPBooleanField class for allows for getting and setting yes/no fields.
129 |
130 | ### Version 0.3 (September 26, 2010)
131 |
132 | * Major performance enhancements when initially loading and getting fields
133 | * New GetSPFields function to return all fields on the page
134 | * Updates to the MakeReadOnly function. Now, it uses a div in order to space out the value and the field's description.
135 | * Internal code updates:
136 | * Rename "Field" property to "Label"
137 | * Consolidated each class args into a single parameter object
138 | * Support for People fields
139 |
140 | ### Version 0.2 (August 31, 2010)
141 |
142 | * _Breaking change_: GetValue for Multi-select choice fields now returns an array of strings rather than a semicolon delimited list ({"["Alpha", "Bravo", "Charlie"](_Alpha_,-_Bravo_,-_Charlie_)"} vs "Alpha; Bravo; Charlie")
143 | * Added the ability to Show/Hide any field (any type of field)
144 | * Added GetValue, SetValue, MakeReadOnly support for the following field types:
145 | * Hyperlink (SPFieldURL)
146 | * Filename fields (default is the Name field in document libraries, aka SPFieldFile)
147 | * Updated [Documentation](Documentation) with usage information for these fields
148 |
149 | ### Version 0.1 (August 19, 2010)
150 |
151 | First release!
152 |
153 | * GetValue, SetValue, MakeReadOnly, Hide and Show support for the following field types:
154 | * Single line of text
155 | * Date and Time (both "Date Only" and "Date & Time")
156 | * Number
157 | * Currency
158 | * Choice (single and multi-select choice fields)
--------------------------------------------------------------------------------
/WikiFiles/docs/Choice fields.md:
--------------------------------------------------------------------------------
1 | ### Choice
2 | {{
3 | // Get a single select dropdown field
4 | var myChoiceField = SPUtility.GetSPField('Single Choice Field');
5 |
6 | // Set the dropdown to Completed
7 | myChoiceField.SetValue('Completed');
8 |
9 | // Gets the value, value = 'Completed'
10 | var value = myChoiceField.GetValue();
11 |
12 | // Make the Title field read only
13 | myChoiceField.MakeReadOnly();
14 |
15 | // Hide the field
16 | myChoiceField.Hide();
17 |
18 | // This is the same for a radio button select field
19 | // The value should be equal to the label displayed next to the radio button in the UI
20 | SPUtility.GetSPField('Radio Button Choice').SetValue('Green');
21 |
22 |
23 | // Multi-select fields are the same except you can call SetValue multiple times
24 | // For example, to check the Alpha, Charlie, and Echo checkboxes:
25 | var myMultiSelectField = SPUtility.GetSPField('Multiselect Column');
26 | myMultiSelectField.SetValue('Alpha');
27 | myMultiSelectField.SetValue('Charlie');
28 | myMultiSelectField.SetValue('Echo');
29 |
30 | // for fill-in fields, simply pass a value that does not exist in the list of choices
31 | myMultiSelectField.SetValue('Christmas'); // Christmas is not a choice so Fill-in gets set
32 |
33 | // GetValue returns an array of strings
34 | var values = myMultiSelectField.GetValue();
35 | // Value = ["Alpha", "Bravo", "Charlie"](_Alpha_,-_Bravo_,-_Charlie_)
36 | }}
--------------------------------------------------------------------------------
/WikiFiles/docs/Common SPField functions.md:
--------------------------------------------------------------------------------
1 | ### SPUtility.js core API
2 |
3 | * **SPUtility.GetSPField(strFieldName)** - Get a field on DispForm, EditForm, or NewForm by the field's display name. Returns an SPField object (see below).
4 | * **SPUtility.GetSPFieldByInternalName(strFieldName)** - Get a field by its internal column name. Returns an SPField object.
5 | * **SPUtility.GetSPFields()** - Get an object containing every field on the page. Field display name is the key and fieldParams is the value. May change in future versions.
6 | * **SPUtility.GetSPFieldsInternal()** - Get an object containing every field on the page. Field internal column name is the key and fieldParams in the value. (added in version 0.14.0)
7 | * **SPUtility.HideSPField(strFieldName)** - Shortcut for hiding a field by display name (faster than GetSPField if you need to hide a ton of fields at once).
8 | * **SPUtility.ShowSPField(strFieldName)** - Shortcut for showing a field by display name (faster than GetSPField if you need to show a ton of fields at once).
9 | * **SPUtility.Setup(settings)** - Configure how SPUtility works. Especially useful for different number formats and/or languages. See [#Setup](#Setup) below for more information. (added in version 0.14.0)
10 |
11 | {{
12 | // GetSPField - The main function! Get a field on the current page using the field's display name
13 | // Returns a SPField object depending on the field's type (see section below)
14 | var myField = SPUtility.GetSPField('Title');
15 |
16 | // NEW! As of 0.9.1, get field's using their internal column name
17 | myField = SPUtility.GetSPFieldByInternalName('Date_x0020_and_x0020_Time');
18 |
19 | // HideSPField - hide a field
20 | SPUtility.HideSPField('Title');
21 |
22 | // ShowSPField - opposite of Hide
23 | SPUtility.ShowSPField('Title');
24 |
25 | // GetSPFields - get an object containing all the fields on the page
26 | var fields = SPUtility.GetSPFields();
27 | for (fieldName in fields) {
28 | // do something with the field
29 | var field = SPUtility.GetSPField(fieldName);
30 | }
31 | }}
32 | ### SPFields
33 | These objects are returned from a call to {{SPUtility.GetSPField}}. All fields support the following functions:
34 | * GetValue - Gets the fields value. *
35 | * SetValue - Sets the fields value. *
36 | * GetDescription - Get a field's description (added in version 0.11.0)
37 | * SetDescription - Set a field's description (added in version 0.11.0)
38 | * MakeReadOnly - Gets the value of the field and replaces any controls with a label preventing the user from editing the field
39 | * MakeEditable - The opposite of MakeReadOnly. Makes a field editable again. Does nothing if the field wasn't read only.
40 | * Hide - Hide's the entire field's row from view.
41 | * Show - Show's the field's row.
42 |
43 | Depending on the type of the field (ex: Choice field or a text field), the functions can perform different operations. SPUtility.js attempts to simplify the interface to each field type as much as possible.
44 |
45 | * Refer to each field's page for more field-specific information (see the matrix on the [Documentation](Documentation) page).
46 |
47 | ### Common SPField Functions
48 |
49 | These functions work nearly identically for each field type:
50 |
51 | {{
52 | // Get the SPField object
53 | var myField = SPUtility.GetSPField('Title');
54 |
55 | // Make the field read only
56 | myField.MakeReadOnly();
57 |
58 | // Allow the user to edit the field again
59 | myField.MakeEditable();
60 |
61 | // Hide the field
62 | myField.Hide();
63 |
64 | // Show the field again
65 | myField.Show();
66 | }}
67 | ### Common SPField Properties
68 |
69 | For each field type, multiple properties are set. These make it easier to reference specific field elements. Every field has the following properties set:
70 |
71 | * Name - Display name of the field
72 | * InternalName - Internal column name
73 | * IsRequired - True if the field is required
74 | * Type - SharePoint field type
75 | * Controls - The element containing all the field's controls
76 | * ControlsRow - The parent table row containing the field's controls
77 | * Label - The element containing the column's name
78 | * LabelRow - The parent table row for the column's name
79 | * ReadOnlyLabel - Default is null, until MakeReadOnly is called, then it holds the reference to the read-only span element
80 |
81 | {{
82 | // get the field
83 | var myField = SPUtility.GetSPField('My Generic Field');
84 |
85 | // Controls references a SPAN element containing all the field specific controls (for example a textbox for Single line of Text fields)
86 | myField.Controls;
87 |
88 | // ControlsRow is generally used only on Survey forms. It references the TR element containing the field's controls. It is null otherwise.
89 | myField.ControlsRow;
90 |
91 | // IsRequired is a boolean value for whether or not the field is required.
92 | myField.IsRequired;
93 |
94 | // Label references the element that contains the display name of the field (ex: My Generic Field, the same value you pass to GetSPField).
95 | myField.Label;
96 |
97 | // LabelRow references the TR element containing the label. This is always set for all forms.
98 | myField.LabelRow;
99 |
100 | // Name is a string containing the fields name (ex: My Generic Field).
101 | myField.Name;
102 |
103 | // ReadOnlyLabel references the DIV for the read only label. It is null until MakeReadOnly is called for the first time.
104 | myField.ReadOnlyLabel;
105 |
106 | // Type is a string containing the fields type (ex: SPFieldText).
107 | myField.Type;
108 | }}
109 |
110 | ### Setup {anchor:Setup}
111 |
112 | Reconfigure SPUtility.js to work with your locale! Here are the default settings which SPUtility.js uses:
113 | {{
114 | {
115 | 'timeFormat': '12HR', // 12HR or 24HR
116 | 'dateSeparator': '/', // separates month/day/year with / or .
117 | 'decimalSeparator': '.', // separates decimal from number
118 | 'thousandsSeparator': ',', // separates thousands in number
119 | 'stringYes': 'Yes', // Text for when boolean field is True
120 | 'stringNo': 'No' // Text for when boolean field is False
121 | }
122 | }}
123 |
124 | The settings are:
125 | * timeFormat - Set the time format to either 12HR or 24HR. When in 12HR mode, dates will be month/day/year. When in 24HR mode, dates will be day/month/year.
126 | * dateSeparator - Set the date separator. Used to separate year from month from day. Ex: 3/10/2015.
127 | * decimalSeparator - Set the decimal separator (usually a period or a comma character) which is used to separate integer from fractional part of a number.
128 | * thousandsSeparator - Set the thousands separator (usually a period or a comma character).
129 | * stringYes - For Yes/No fields, the text to display when the field is in read-only mode and the field is checked.
130 | * stringNo - For Yes/No fields, the text to display when the field is in read-only mode and the field is NOT checked.
131 |
132 | For example, someone in Spain might want to change the settings to:
133 | {{
134 | SPUtility.Setup({
135 | 'timeFormat': '24HR',
136 | 'decimalSeparator': ',',
137 | 'thousandsSeparator': '.',
138 | 'stringYes': 'Si',
139 | });
140 | }}
141 |
142 | ### Deprecated methods (will be removed in a later release)
143 |
144 | * **SPUtility.GetTimeFormat()** - Gets the time format which is used to format date/time fields. '12HR' (default) or '24HR'. (added in version 0.11.0)
145 | * **SPUtility.SetTimeFormat(format)** - Set the time format to either 12HR or 24HR. When in 12HR mode, dates will be month/day/year. When in 24HR mode, dates will be day/month/year. (added in version 0.11.0)
146 | * **SPUtility.GetDateSeparator()** - Get the date separator. Default is '/'. (added in version 0.11.2)
147 | * **SPUtility.SetDateSeparator(separator)** - Set the date separator. Used to separate year from month from day. Ex: 3/10/2015. (added in version 0.11.2)
148 | * **SPUtility.GetDecimalSeparator()** - Get the decimal separator. Default is a period '.' (added in version 0.13.0)
149 | * **SPUtility.SetDecimalSeparator(separator)** - Set the decimal separator (usually a period or a comma character) which is used to separate integer from fractional part of a number. (added in version 0.13.0)
150 | * **SPUtility.GetThousandsSeparator()** - Get the thousands separator. Default is a comma ',' (added in version 0.13.0)
151 | * **SPUtility.SetThousandsSeparator(separator)** - Set the thousands separator (usually a period or a comma character). (added in version 0.13.0)
152 |
--------------------------------------------------------------------------------
/WikiFiles/docs/Content Type fields.md:
--------------------------------------------------------------------------------
1 | ### Description (as of version 0.9.1)
2 | The Content Type field is a special field that only appears once multiple content types have been enabled on a list.
3 |
4 | ### Usage
5 |
6 |
7 | {code:javscript}
8 | // On EditForm, a Content Type field is displayed but it won't be available on NewForm
9 | // If you try to get the field on NewForm, an exception will be thrown and then logged below
10 | var field = SPUtility.GetSPField('Content Type');
11 |
12 | // Hide the field
13 | field.Hide();
14 |
15 | // Make the field read only
16 | //field.MakeReadOnly();
17 |
18 | // Set the value using the display name
19 | field.SetValue('Item');
20 |
21 | // ... or the content type ID!
22 | field.SetValue('0x0100DBD234B62463314F8DE3C4AA2635CD51');
23 |
24 | // Setting the value does not force the page postback
25 | // if you want to trigger the postback, use the Dropdown onchange
26 | field.Dropdown.onchange();
27 | {code:javscript}
28 |
29 | Check out a code example here: https://github.com/kitmenke/sputility/blob/master/examples/contenttype.html.
--------------------------------------------------------------------------------
/WikiFiles/docs/Date fields.md:
--------------------------------------------------------------------------------
1 | Note: As of v0.10.0, SPUtility.js supports both the 12 hour format (3/14/2014 1:00 AM) and the 24 hour format (14/03/2014 01:00).
2 |
3 | **Note for those using a 24 hour date format:** By default, SPUtility.js uses the 12 hour date format. You will need to call SetTimeFormat before the rest of your code to use the 24 hour date format:
4 |
5 | SPUtility.SetTimeFormat('24HR');
6 |
7 | If you use a separator other than a "/" for your dates, for example 10.03.2015, then call SetDateSeparator:
8 |
9 | SPUtility.SetDateSeparator('.');
10 |
11 | ### Date
12 | {{
13 | // Date fields (no time value)
14 | var myDateField = SPUtility.GetSPField('Date Field');
15 |
16 | // Set the year (2010), month (august), day (13)
17 | myDateField.SetValue(2010, 8, 13);
18 |
19 | // GetValue returns a SPDateTimeFieldValue object
20 | // Note: As of 0.9.1, the properties will always be numbers (not strings)
21 | var value = myDateField.GetValue();
22 | // value.Year = 2014
23 | // value.Month = 3
24 | // value.Day = 14
25 | // value.IsTimeIncluded = false
26 | // Note: As of 0.10.0, there is a new TimeFormat property for 12HR or 24HR formats
27 | // value.TimeFormat = '12HR'
28 | // value.toString() => '3/14/2014'
29 | // ----- or ----
30 | // value.TimeFormat = '24HR'
31 | // value.toString() => '14/03/2014'
32 |
33 |
34 | // Make the field read only
35 | myDateField.MakeReadOnly();
36 |
37 | // Hide the field
38 | myDateField.Hide();
39 | }}
40 | ### Date and Time
41 | {{
42 | // Date & Time field
43 | var myDateTimeField = SPUtility.GetSPField('Date Time Field');
44 |
45 | // Sets the value to 8/13/2010 1:30PM
46 | // Should match the values in the time dropdowns
47 | // Hour Ex: 12 PM or 3 AM
48 | // Time Ex: 00, 25, 35 (increments of 5 from 00 to 55)
49 | // Last two parameters should be strings
50 | myDateTimeField.SetValue(2010, 8, 12, '3 PM', '55');
51 |
52 | // Gets a SPDateTimeFieldValue object
53 | // Note: As of 0.9.1, the properties will always be numbers (not strings)
54 | var value = myDateTimeField.GetValue();
55 | // value.Year = 2010
56 | // value.Month = 8
57 | // value.Day = 12
58 | // value.Hour = 15
59 | // value.Minute = 55
60 | // value.IsTimeIncluded = true
61 | // value.toString() => 8/12/2010 3:55PM
62 |
63 | // Set only the date portion (as of 0.9.1)
64 | myDateTimeField.SetDate(2010, 8, 12);
65 |
66 | // Set only the time portion using numbers or strings! (as of 0.9.1)
67 | myDateTimeField.SetTime(8, 30); // 8:30 AM
68 | myDateTimeField.SetTime(15, 0); // 3:00 PM
69 | myDateTimeField.SetTime('5 PM', '55'); // 5:55 PM
70 |
71 | // Make the field read only
72 | myDateTimeField.MakeReadOnly();
73 |
74 | // Hide the field
75 | myDateTimeField.Hide();
76 | }}
77 | Set a DateTime field to "now":
78 | {{
79 | // default contact date to "today"
80 | var today = new Date();
81 | var hour = today.getHours();
82 | if (hour > 12) {
83 | hour = (hour - 12) + " PM";
84 | } else {
85 | hour += " AM";
86 | }
87 | // round the current minute down to the nearest 5 minutes
88 | var minute = today.getMinutes();
89 | minute = minute - (minute % 5);
90 | SPUtility.GetSPField('Contact Date').SetValue(today.getFullYear(), today.getMonth()+1, today.getDate(), hour, minute);
91 | }}
--------------------------------------------------------------------------------
/WikiFiles/docs/Documentation.html:
--------------------------------------------------------------------------------
1 |
2 |
For instructions on how to install SPUtility.js, see Installation.
3 |
Hello world!
4 |
Here is a complete hello world example:
5 |
<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.2.min.js"></script>
6 | <script src="/[change to your subsite]/SiteAssets/sputility.min.js"></script>
7 | <script>
8 | // wait for the window to load
9 | $(document).ready(function () {
10 | // EXAMPLE: Set the value of the Title field to Hello world!
11 | SPUtility.GetSPField('Title').SetValue('Hello world!');
12 | });
13 | </script>
14 |
You could upload this as a HTML file into your SiteAssets library alongside sputility.min.js (adjust src paths as necessary).
Here is a list of all the supported field tables and the various way they are displayed in SharePoint. SPUtility.js does all the hard work of figuring out to show/hide, get/set values, and make them read only!
As of June 2016, version 0.14.2 is the final release of SPUtility.js and I will no longer be actively maintaining this project. Thank you to everyone who helped make this project a success!
4 |
As always, the code is available on
5 | GitHub so please feel free to fork / modify it yourself.
6 |
Description:
7 |
SPUtility.js is a JavaScript library used to make modifications to SharePoint's list forms (NewForm.aspx and EditForm.aspx in a survey, custom list or library). It works with SharePoint 2007, 2010, and 2013 (including SharePoint Online / Office 365).
Keep in mind that SPUtility.js and documentation are still a work in progress... and that it won't work in every situation. It currently will NOT work with:
To use the library, you can just upload SPUtility.js and dependent files into a document library and put a Content Editor Web Part with some JavaScript code on whichever page you want to modify! Detailed instructions are on the
35 | Installation page.
36 |
See the Documentation for the matrix of supported fields and API documentation. Browse the
37 | Changelog to see the list of updates.
38 |
If you do find something that you would like supported or isn't quite working, please don't hesitate to post a
39 | Discussion.
40 |
Finally, if you use SPUtility.js and like it, tweet at me!
41 | @kitmenke
Before
53 |
54 |
55 | SPUtility.GetSPField('Status').MakeReadOnly();
56 |
57 | After
58 |
59 |
Hide a field from view
60 |
Before
61 |
62 |
63 | SPUtility.GetSPField('% Complete').Hide();
64 |
65 | After
66 |
67 |
68 | See the Documentation for more information.
69 |
--------------------------------------------------------------------------------
/WikiFiles/docs/Home_sputility_assignedto.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/docs/Home_sputility_assignedto.png
--------------------------------------------------------------------------------
/WikiFiles/docs/Home_sputility_assignedto_readonly.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/docs/Home_sputility_assignedto_readonly.png
--------------------------------------------------------------------------------
/WikiFiles/docs/Home_sputility_hide_after.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/docs/Home_sputility_hide_after.png
--------------------------------------------------------------------------------
/WikiFiles/docs/Home_sputility_hide_before.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/docs/Home_sputility_hide_before.png
--------------------------------------------------------------------------------
/WikiFiles/docs/Home_sputility_status.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/docs/Home_sputility_status.png
--------------------------------------------------------------------------------
/WikiFiles/docs/Home_sputility_status_readonly.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/docs/Home_sputility_status_readonly.png
--------------------------------------------------------------------------------
/WikiFiles/docs/Home_sputility_title.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/docs/Home_sputility_title.png
--------------------------------------------------------------------------------
/WikiFiles/docs/Home_sputility_title_readonly.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/docs/Home_sputility_title_readonly.png
--------------------------------------------------------------------------------
/WikiFiles/docs/Installation.md:
--------------------------------------------------------------------------------
1 | # Installation
2 |
3 | The steps below are targeted towards installing the jQuery version of SPUtility on a SharePoint site.
4 |
5 | **SharePoint 2013 Note:** SPUtility.js will not work with Minimal Download Strategy (MDS) enabled in SharePoint 2013 (if you see start.aspx it is currently enabled). To disable, go to Site Settings -> Manage Site Features -> Deactivate Minimal Download Strategy.
6 |
7 | For more troubleshooting information see [Troubleshooting](Troubleshooting)
8 |
9 | ## SharePoint 2010 / 2013 / SharePoint Online (Office 365)
10 |
11 | **Step 1:** Download [jQuery](http://jquery.com/download/). Version 1.x is recommend for maximum browser compatibility.
12 | **Step 2:** Download [sputility.min.js](https://raw.github.com/kitmenke/sputility/master/dist/sputility.min.js). For development, you can use [sputility.js](https://raw.github.com/kitmenke/sputility/master/dist/sputility.js) instead (uncompressed version for easier debugging).
13 | **Step 3:** Upload both files into a document library in your SharePoint site.
14 | **Step 4:** Create a new HTML file with your SPUtility.js script. For example, [helloworld.html](https://raw.github.com/kitmenke/sputility/master/examples/helloworld.html) and upload that to your document library as well.
15 | **Step 5:** Navigate to the list form you want to modify. In the ribbon, click on List then Form Web Parts and choose the form you want to edit (ex: New Form, Edit Form).
16 | 
17 | **Step 6:** Add a Content Editor web part to the page.
18 | 
19 | **Step 7:** Edit Content Editor's web part properties:
20 | * For Content Link, paste in the URL to your HTML file. Ex: /kitsite/Files/helloworld.html
21 | * Under the Appearance section, you will probably also want to set Chrome Type to None so your end users won't see an empty web part.
22 | 
23 | **Step 8:** Click the OK button and then click Stop Editing in the ribbon. You're done!
24 |
25 | Note: **+Do NOT click the Apply button+**, you must click the OK button!
26 |
27 | You should now be able to go back into your form and see "Hello World" populated
28 | 
29 |
30 | ## SharePoint 2007
31 |
32 | **Step 1-3:** _Steps are the same as above_
33 |
34 | **Step 4:** Navigate to form (EditForm.aspx or NewForm.aspx)
35 |
36 | You can just create/edit/view any item in the list to get to the right form.
37 |
38 | Alternatively, navigate directly to the page using a direct URL. For example: https://example.sharepoint.com/Lists/Test%20List/NewForm.aspx
39 | https://example.sharepoint.com/Lists/Test%20List/EditForm.aspx
40 | https://example.sharepoint.com/Lists/Test%20List/DispForm.aspx
41 |
42 | **Step 5:** Edit the page
43 |
44 | Click Site Actions -> Edit Page.
45 |
46 | If the Edit Page option is missing, use the ToolPaneView=2 URL parameter. For example, https://example.sharepoint.com/Lists/Test%20List/EditForm.aspx?ToolPaneView=2)
47 |
48 | **Step 6:** Add a Content Editor Web Part to the page
49 |
50 | **Step 7:** Edit the web part. Click Edit -> Modify shared web part
51 |
52 | **Step 8:** Edit the content editor's HTML to add some JavaScript. Click Source Editor and paste in your code. For example, you can paste the contents of [helloworld.html](https://raw.github.com/kitmenke/sputility/master/examples/helloworld.html) into your content editor.
53 |
54 | **Step 9:** You're done! Save the page / stop editing.
55 |
56 | ### Alternative Installation Options
57 |
58 | If you don't want to add a content editor to each form, you can also edit the pages using SharePoint Designer and include your scripts that way. This is not recommended unless you are already customizing the page for a different reason.
59 |
60 | ### Advanced Options for Running SPUtility.js
61 |
62 | #### After the whole page has loaded (SharePoint)
63 |
64 | You can use a SharePoint JavaScript function to run your code:
65 | {{
66 | function MyCustomExecuteFunction()
67 | {
68 | // your code here...
69 | }
70 | _spBodyOnLoadFunctionNames.push("MyCustomExecuteFunction");
71 | }}
72 |
73 | #### After the whole page has loaded (jQuery)
74 |
75 | You can use jQuery to wait until the entire page has loaded:
76 | {{
77 | $(window).load(function () {
78 | // your code here...
79 | });
80 | }}
81 |
82 | #### Before the entire page is loaded, when the DOM is ready (jQuery)
83 |
84 | A slightly faster option, is using $(document).ready(..). This executes as soon as the DOM is ready (before the window loads). [http://learn.jquery.com/using-jquery-core/document-ready/](http://learn.jquery.com/using-jquery-core/document-ready/).
85 | {{
86 | $(document).ready(function() {
87 | // your code here...
88 | });
89 | }}
90 |
91 | #### Immediately after your form is loaded
92 |
93 | This is the fastest and most advanced method.
94 |
95 | If you have a lot of JavaScript code, you may notice the page changing after it loads (as SPUtility works its magic). If you don't want users to see this, you can do the following:
96 | # Move your Content Editor Web Part below the form (it must be **below** the List View Web Part)
97 | # Put your code directly in between the script tags:
98 | {{
99 |
102 | }}
103 | This will force your JavaScript to run immediately. If you don't put the Content Editor below the form, the JavaScript will load before the form has loaded and you will get JavaScript errors.
--------------------------------------------------------------------------------
/WikiFiles/docs/Installation_2013-add-content-editor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/docs/Installation_2013-add-content-editor.png
--------------------------------------------------------------------------------
/WikiFiles/docs/Installation_2013-content-link.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/docs/Installation_2013-content-link.png
--------------------------------------------------------------------------------
/WikiFiles/docs/Installation_2013-form-web-parts.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/docs/Installation_2013-form-web-parts.png
--------------------------------------------------------------------------------
/WikiFiles/docs/Installation_2013-title-hello-world.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/docs/Installation_2013-title-hello-world.png
--------------------------------------------------------------------------------
/WikiFiles/docs/Installation_sp2010-default-edit-form.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/docs/Installation_sp2010-default-edit-form.PNG
--------------------------------------------------------------------------------
/WikiFiles/docs/Lookup fields.md:
--------------------------------------------------------------------------------
1 | ### Description
2 | Lookup fields display in three modes depending on list settings and the number of lookup items:
3 |
4 | * Small single select lookup
5 | * Large single select lookup
6 | * Multi select lookup
7 |
8 | ### Usage
9 |
10 | See [Common SPField functions](Common-SPField-functions) for generic functions and properties.
11 |
12 | #### Small single select lookup
13 | This field displays as a dropdown using a SELECT when allow multiple values = No and there are less than 20 values in the lookup list.
14 |
15 | {{
16 | // get the field
17 | var smallLookup = SPUtility.GetSPField('Small Lookup');
18 |
19 | // set the value using the lookup list item's ID
20 | smallLookup.SetValue(6);
21 |
22 | // set the value using the text
23 | smallLookup.SetValue('Indigo');
24 |
25 | // Gets the dropdown's text value as a string (Ex: Indigo)
26 | var value = smallLookup.GetValue();
27 | }}This field has the Dropdown property set:
28 | {{
29 | var smallLookup = SPUtility.GetSPField('Small Lookup');
30 |
31 | // Dropdown references the SELECT element for the field.
32 | smallLookup.Dropdown;
33 | }}
34 | #### Large single select lookup
35 | This field displays as an autocomplete using a text INPUT box when Allow multiple values = No, there are 20 or more values, and your browser is Internet Explorer. If a different browser is used, the field displays as a dropdown (will work like a small single select lookup).
36 |
37 | {{
38 | // get the field
39 | var largeLookup = SPUtility.GetSPField('Large Lookup');
40 |
41 | // set the value using the lookup list item's ID
42 | largeLookup.SetValue(24);
43 |
44 | // set the value using the text
45 | largeLookup.SetValue('Xray');
46 |
47 | // Gets the textbox's value as a string (Ex: Xray)
48 | var value = smallLookup.GetValue();
49 | }}This field has the Textbox property set:
50 | {{
51 | var largeLookup = SPUtility.GetSPField('Large Lookup');
52 |
53 | // Textbox references the autocomplete INPUT element for the field.
54 | largeLookup.Textbox;
55 | }}
56 | #### Multi-select lookup
57 | This field displays as two list boxes with Add and Remove buttons when Allow multiple values = Yes.
58 |
59 | {{
60 | // get the field
61 | var multiLookup = SPUtility.GetSPField('Multi-select Lookup');
62 |
63 | // set the value using the lookup list item's ID
64 | multiLookup.SetValue(7);
65 |
66 | // set the value using the text
67 | multiLookup.SetValue('Violet');
68 |
69 | // to remove a value, add an additional parameter
70 | multiLookup.SetValue(7, false);
71 | multiLookup.SetValue('Violet', false);
72 |
73 | // Gets the currently selected values as an array of strings (ex: [ 'Violet', 'Orange' ](-'Violet',-'Orange'-))
74 | var value = smallLookup.GetValue();
75 | }}This field has four additional properties set:
76 | {{
77 | var largeLookup = SPUtility.GetSPField('Large Lookup');
78 |
79 | // ListChoices references the SELECT element of values that can be added
80 | largeLookup.ListChoices;
81 |
82 | // ListSelections references the SELECT element of values that can be removed (the current selections)
83 | largeLookup.ListSelections;
84 |
85 | // ButtonAdd references the BUTTON element to add items
86 | largeLookup.ButtonAdd;
87 |
88 | // ButtonRemove references the BUTTON element to remove items
89 | largeLookup.ButtonRemove;
90 | }}
91 |
--------------------------------------------------------------------------------
/WikiFiles/docs/People fields.md:
--------------------------------------------------------------------------------
1 | ### People or Group
2 |
3 | Note 5/8/2014: SetValue is not working in SharePoint 2007. Mostly working in SharePoint 2013 but still seems to have issues.
4 |
5 | SetValue sets the field's inputs and then simulates a click on the "Check Names" button. It does NOT do any sort of validation, so using a user's account name is recommended. Also, you may notice a slight delay when setting the value; this is caused by the Check Names button validating the input.
6 |
7 | {{
8 | // Get the field
9 | var peopleField = SPUtility.GetSPField('Assigned To');
10 |
11 | // Set the field's value
12 | // The value can be either of the following:
13 | // 1. The user's account name
14 | // Don't forget to escape your backslash!
15 | peopleField.SetValue('domain\\myuserid');
16 | // 2. The user's EXACT display name (if it isn't exact then it won't work!)
17 | peopleField.SetValue('Menke, Kit');
18 | // You can use the display name method for groups (if it is enabled for your field)
19 | peopleField.SetValue('Approvers');
20 |
21 | // For multi-select fields, separate your values using semicolons (for people or groups):
22 | peopleField.SetValue('Approvers;Designers');
23 |
24 | // Gets the value of the people field
25 | var value = peopleField.GetValue();
26 |
27 | // Make the people field read only
28 | peopleField.MakeReadOnly();
29 |
30 | // Allow the user to edit the field again
31 | peopleField.MakeEditable();
32 |
33 | // Hide the field
34 | peopleField.Hide();
35 | }}
--------------------------------------------------------------------------------
/WikiFiles/docs/Text fields.md:
--------------------------------------------------------------------------------
1 | ### Description
2 | Text fields are displayed as a textbox. They work similarly for each of these types:
3 |
4 | * Single line of text
5 | * Number
6 | * Currency
7 | * SPFieldFile (Document library "Name" field)
8 |
9 | ### Usage
10 |
11 | See [Common SPField functions](Common-SPField-functions) for generic functions and properties.
12 |
13 | #### Single line of text
14 | {{
15 | var field = SPUtility.GetSPField('Title');
16 | field.SetValue('Hello world!');
17 |
18 | // GetValue returns a string
19 | var value = field.GetValue();
20 | }}
21 | #### Number
22 | {{
23 | var field = SPUtility.GetSPField('Number Field');
24 | field.SetValue(42);
25 |
26 | // GetValue returns a number
27 | var value = field.GetValue();
28 | }}
29 | #### Currency
30 | {{
31 | var field = SPUtility.GetSPField('Currency Field');
32 | field.SetValue('$97.95');
33 |
34 | // GetValue returns a number (ex: 97.95)
35 | var value = field.GetValue();
36 |
37 | // GetFormattedValue returns a formatted string (ex: $97.95)
38 | value = field.GetFormattedValue();
39 | }}
40 | #### SPFieldFile (Document library "Name" field)
41 | {{
42 | var field = SPUtility.GetSPField('Name');
43 | field.SetValue('My Document Name');
44 |
45 | // GetValue returns a string
46 | var value = field.GetValue();
47 | }}
--------------------------------------------------------------------------------
/WikiFiles/docs/Troubleshooting.md:
--------------------------------------------------------------------------------
1 | The most common problems people encounter are during installation.
2 |
3 | # Check to make sure SPUtility.js and jQuery are being loaded
4 |
5 | Any code you write is dependent on the jQuery and SPUtility libraries being loaded on the page. If they aren't, your code won't work and you'll get an error.
6 |
7 | Symptoms:
8 | * Uncaught ReferenceError: SPUtility is not defined
9 | * Uncaught ReferenceError: jQuery is not defined
10 |
11 | # Navigate to your form. For NewForm.aspx click the New Item button. For EditForm.aspx, create an item in your list and then edit it by clicking the "..." and choosing Edit.
12 | # Press F12 in your browser to bring up the Developer Tools
13 | # Go to the Console tab
14 | # Type in "jQuery"
15 |
16 | If it works, you'll get a function returned in the console: function (a,b){return new m.fn.init(a,b)}
17 |
18 | Good:
19 | 
20 |
21 | Bad:
22 | 
23 |
24 | # +SharePoint 2013:+ Disable Minimal Download Strategy (MDS)
25 |
26 | If you see "/_layouts/15/start.aspx" in the URL of your SharePoint site, it is currently enabled. Before you disable MDS, you need to consider whether or not you need it enabled. Unfortunately, I haven't been able to get SPUtility.js to work with it (if you have a solution let me know!).
27 |
28 | What is MDS? Check out [https://msdn.microsoft.com/en-us/library/office/dn456544.aspx](https://msdn.microsoft.com/en-us/library/office/dn456544.aspx)
29 |
30 | To disable, go to Site Settings -> Manage Site Features -> Deactivate Minimal Download Strategy. This is a per-site setting so you will need to disable it on any site which you are planning to use SPUtility.js on.
--------------------------------------------------------------------------------
/WikiFiles/docs/Troubleshooting_sputility-chrome-console-bad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/docs/Troubleshooting_sputility-chrome-console-bad.png
--------------------------------------------------------------------------------
/WikiFiles/docs/Troubleshooting_sputility-chrome-console.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/docs/Troubleshooting_sputility-chrome-console.png
--------------------------------------------------------------------------------
/WikiFiles/docs/URL Fields.md:
--------------------------------------------------------------------------------
1 | ### Hyperlink
2 | {{
3 | // Get the hyperlink field
4 | var hyperlinkField = SPUtility.GetSPField('Hyperlink Field');
5 |
6 | // Set the field to link (shamelessly) to SPUtility.js on codeplex
7 | hyperlinkField.SetValue('http://sputility.codeplex.com', 'SPUtility.js');
8 |
9 | // Gets the value of the hyperlink field as an array
10 | var values = hyperlinkField.GetValue();
11 | // values[0](0) = 'http://sputility.codeplex.com'
12 | // values[1](1) = 'SPUtility.js'
13 |
14 | // Make the hyperlink field read only, displays as a clickable hyperlink
15 | hyperlinkField.MakeReadOnly();
16 | // also there is the ability to display the text only (no hyperlink)
17 | // will display as "http://sputility.codeplex.com, SPUtility.js"
18 | hyperlinkField.MakeReadOnly( { TextOnly: true } );
19 |
20 | // Hide the field
21 | hyperlinkField.Hide();
22 | }}
--------------------------------------------------------------------------------
/WikiFiles/docs/Yes_No fields.md:
--------------------------------------------------------------------------------
1 | ### Yes/No (boolean)
2 | {{
3 | // Get the "Is important?" field
4 | var myBoolField = SPUtility.GetSPField('Is important?');
5 |
6 | // Set the field to "yes" (checked)
7 | myBoolField.SetValue(true);
8 | // Set the field to "no" (not checked)
9 | myBoolField.SetValue(false);
10 |
11 | // Get the value: true or false
12 | var value = myBoolField.GetValue();
13 |
14 | // Make the field read only
15 | myBoolField.MakeReadOnly();
16 |
17 | // Allow the user to edit the field again
18 | myBoolField.MakeEditable();
19 |
20 | // Hide the field
21 | myBoolField.Hide();
22 | }}
--------------------------------------------------------------------------------
/WikiFiles/raw/Changelog.codeplexwiki:
--------------------------------------------------------------------------------
1 | !!! Version 0.14.2 (April 19, 2016)
2 | * Corrected version number string in file header
3 |
4 | !!! Version 0.14.1 (April 18, 2016)
5 | * BUG: Fix empty Number fields displaying as NaN when in read only mode
6 | * BUG: Fix date and time fields which have no date displaying the time only in read only mode
7 |
8 | !!! Version 0.14.0 (March 30, 2016)
9 | * FEATURE: Add ability to configure SPUtility.js with SPUtility.Setup(...)
10 | * FEATURE: Allow customizing Yes/No field (SPBooleanField) string values. (Thank you szykov!)
11 | * FEATURE: Improvement to SPUserField2013 to display links to users instead of just text. (Thank you szykov!)
12 | * FEATURE: Allow getting the hashtable of all fields by internal name using SPUtility.GetSPFieldsInternal() (Thank you ViktorHofer!)
13 | * DEPRECATED: The following functions will be removed in a future release: GetThousandsSeparator, SetThousandsSeparator, GetDecimalSeparator, SetDecimalSeparator, GetDateSeparator, SetDateSeparator, GetTimeFormat, and SetTimeFormat. Use SPUtility.Setup(...) instead!
14 | * BUG: SPUserField2013 read only label should now be updated correctly if the value is changed.
15 | * Huge refactoring of internal field creation. This helps especially for getting fields by their internal column name. (Thank you ViktorHofer!)
16 |
17 | !!! Version 0.13.0 (March 22, 2016)
18 | * FEATURE (or bug?): Support for different thousands and decimal separators using SetDecimalSeparator and SetThousandsSeparator (thank you ViktorHofer!)
19 | * FEATURE: Full support for GetValue and SetValue on DispForm for fields which display as text (Text, Number, Date, most Choice fields, Yes/No) via a new class: SPDispFormTextFields. Note:
20 | * BUG: Fix detection of DispForm especially for document libraries.
21 | * BUG: Fix read-only label not updating for SP 2013 people fields (thank you ViktorHofer!)
22 | * Added soooo many unit tests....
23 |
24 | !!! Version 0.12.0 (February 28, 2016)
25 | * BREAKING CHANGE: LabelRow and ControlsRow properties no longer return the jquery object but instead return the TR element itself.
26 | * BUG: Fix Survey support in SharePoint 2013
27 | * BUG: Fix MakeReadOnly method on people fields in SharePoint 2013
28 | * FEATURE: Support for GetValue on DispForm via a new special type
29 | * FEATURE: Add InternalName property to all fields (thank you RawkBob!)
30 |
31 | !!! Version 0.11.2 (March 10, 2015)
32 | * BUG / FEATURE: Date separator for date/time fields was hard coded to a '/'. Added a new function, SPUtility.SetDateSeparator, which allows the user to change it.
33 | * BUG: SetDescription not working in SharePoint 2007
34 |
35 | !!! Version 0.11.1 (February 26, 2015)
36 | * BUG: Issue with getting current SharePoint version breaks the library
37 |
38 | !!! Version 0.11.0 (February 23, 2015)
39 | * FEATURE: Add GetDescription and SetDescription to SPField. Allows you to manipulate descriptions for any field type!
40 | * FEATURE: Add SPFieldBusinessData
41 | * BUG: More fixes for SharePoint 2007/2010 SPUserField
42 | Big thanks to Onizet for the contributions! [url:https://sputility.codeplex.com/discussions/580446]
43 |
44 | !!! Version 0.10.0 (February 12, 2015)
45 | * FEATURE: Support for 24 hour time format with date and time fields!
46 | * FEATURE: Support for people fields in SharePoint 2013!
47 | * BUG: Fix spacing and padding with 12 hour time formats.
48 | * BUG: Fix selectors in SPUserField (thanks onizet!)
49 | * More examples added!
50 |
51 | !!! Version 0.9.4 (November 9, 2014)
52 | * BUG: Yes/No fields should display "Yes" or "No" instead of true or false after calling MakeReadOnly.
53 | * BUG: Yes/No fields - SetValue not working correctly.
54 |
55 | !!! Version 0.9.3 (September 29, 2014)
56 | * BUG: Checkbox fields should allow unchecking a field by passing a second boolean parameter set to false.
57 |
58 | !!! Version 0.9.2 (July 1, 2014)
59 | * BUG: Should allow getting field names that are one character.
60 |
61 | !!! Version 0.9.1 (May 8, 2014)
62 | * FEATURE: Get fields using their internal column name: GetSPFieldByInternalName. See [Common SPField functions]
63 | * FEATURE: DateTime fields now have two special methods: SetDate and SetTime. This allows you to set (or reset) the date or time individually. Also, both methods now support integer and string values! Also, calling GetValue will consistently return a SPDateTimeFieldValue object with integer properties for year, month, day, hour, and minute. See [Date fields]
64 | * FEATURE/BUG: GetSPField now supports being able to retrieve the Content Type field see [Content Type fields]
65 |
66 | !!! Version 0.9.0 (April 2, 2014)
67 | * BUG: Should be able to make mult-select lookup fields read-only (fixes #6).
68 | * Refactored read-only methods to be class-level methods.
69 | * CHANGE: Deprecate Debug mode (throw exceptions instead).
70 | * BUG: Added HideSPField, ShowSPField, and GetSPFields public methods back.
71 | * Refactored how global SPUtility variable is set(again).
72 | * BUG: When a field is read-only, setting the value should update the label
73 | * Added examples
74 |
75 | !!! Version 0.8.4 (now with 100% more jQuery!!!) (March 4, 2014)
76 | * Complete re-implementation of SPUtility using jQuery instead of prototype.js.
77 | * QUnit tests implemented for all of the fields
78 | * Ability to clear a date field after it has been set by passing null
79 | * Support for SharePoint 2013
80 |
81 | *Prototype.js version discontinued and superseded by the jQuery version.*
82 |
83 | !!! Version 0.8.2 (bug-fix update) (March 9, 2013):
84 | * BUG: Fixed not being able to Hide fields on DispForm.aspx
85 | * BUG: Fixed Large Lookup fields not saving value correctly (thank you lambi_uk!)
86 | * BUG: Fixed not being able to call SetValue for Large Lookup fields when the value contained a space (thank you MarkETolley!)
87 |
88 | !!! Version 0.8.1 (bug fix update) (April 23, 2012)
89 | * BUG: Fixed problem with making empty date fields read only
90 | * BUG: Fixed problem where setting the value of a read only field now didn't update the label
91 | * FEATURE: Can now pass a string to a SPDateTimeField to set the date textbox
92 |
93 | !!! Version 0.8 (April 26, 2011)
94 | * FEATURE: Support for rich text fields
95 | * FEATURE: Support for choice fields with fill-in values
96 | * BUG: Support for unchecking multi-select checkboxes
97 |
98 | !!! Version 0.7 (February 6, 2011)
99 | * FEATURE: New SPLookupMultiField class to support multi-select lookup fields. Also various improvements to allow setting the values using list item ID or the text value for all Lookup fields.
100 | * BUG: Fixed chaining after SetValue for single select lookup fields
101 | * CHANGE: Refactored _makeReadOnly to be a private function
102 |
103 | !!! Version 0.6 (January 31, 2011)
104 | * FEATURE: SPUtility now can detect and load supported fields on Survey forms.
105 | * FEATURE: New HideSPField and ShowSPField functions. These functions function the same as SPField.Hide/Show except the entire field won't be initialized. This can be useful on very large forms that only need to show/hide fields (ex: tabs).
106 | * FEATURE: Debug function for troubleshooting: call SPUtility.Debug(true) before your SPUtility code to show alerts (firebug console messages if possible).
107 | * UPDATE: getSPFieldType optimized.
108 | * UPDATE: Fields are now initialized when GetSPField is called (not before).
109 | * BUG: The function 'createSPField' no longer throws an error: problem where if a field had a problem, any fields after would not be detected.
110 | * UPDATE: Updates to SPChoiceField to detect when the field allows for Fill-in values (partial support, currently can set the normal options but not Fill-in values yet)
111 |
112 | !!! Version 0.5 (January 8, 2011)
113 | * Bug: SPNumberField GetValue() function now disregards commas
114 | * _Breaking change_: GetSPFields will now return a hashtable instead of the array (see next item)
115 | * GetSPField now loads fields into a hashtable instead of an array (dramatically increases speed for forms with a large number of fields)
116 | * GetSPFieldType now attempts to prevent throwing an error when unable to get the field's type (allows for easier Firebugging).
117 | * New MakeEditable function, will undo MakeReadOnly
118 | * Support for currency fields. MakeReadOnly will display the value with dollar sign, and commas. Uses formatMoney function made by Jonas Raoni Soares Silva.
119 | * Support for single select lookup fields
120 | * Reformatted code to meet higher JSLint standards
121 |
122 | !!! Version 0.4 (November 13, 2010)
123 |
124 | * Bug: Unable to update the read only label. Fix allows developer to call MakeReadOnly again to update the label.
125 | * Bug: Getting the value of a number field would sometimes return a string. GetValue now will always return a number.
126 | * GetSPField now will throw a helpful error if the field is not found.
127 | * Support for *plain text* "Multiple lines of text" fields (SPFieldNote). Support for the rich text versions is still a work in progress.
128 | * Support for Yes/No fields. New SPBooleanField class for allows for getting and setting yes/no fields.
129 |
130 | !!! Version 0.3 (September 26, 2010)
131 |
132 | * Major performance enhancements when initially loading and getting fields
133 | * New GetSPFields function to return all fields on the page
134 | * Updates to the MakeReadOnly function. Now, it uses a div in order to space out the value and the field's description.
135 | * Internal code updates:
136 | ** Rename "Field" property to "Label"
137 | ** Consolidated each class args into a single parameter object
138 | * Support for People fields
139 |
140 | !!! Version 0.2 (August 31, 2010)
141 |
142 | * _Breaking change_: GetValue for Multi-select choice fields now returns an array of strings rather than a semicolon delimited list ({"["Alpha", "Bravo", "Charlie"]"} vs "Alpha; Bravo; Charlie")
143 | * Added the ability to Show/Hide any field (any type of field)
144 | * Added GetValue, SetValue, MakeReadOnly support for the following field types:
145 | ** Hyperlink (SPFieldURL)
146 | ** Filename fields (default is the Name field in document libraries, aka SPFieldFile)
147 | * Updated [Documentation] with usage information for these fields
148 |
149 | !!! Version 0.1 (August 19, 2010)
150 |
151 | First release!
152 |
153 | * GetValue, SetValue, MakeReadOnly, Hide and Show support for the following field types:
154 | ** Single line of text
155 | ** Date and Time (both "Date Only" and "Date & Time")
156 | ** Number
157 | ** Currency
158 | ** Choice (single and multi-select choice fields)
--------------------------------------------------------------------------------
/WikiFiles/raw/Choice fields.codeplexwiki:
--------------------------------------------------------------------------------
1 | !!! Choice
2 | {{
3 | // Get a single select dropdown field
4 | var myChoiceField = SPUtility.GetSPField('Single Choice Field');
5 |
6 | // Set the dropdown to Completed
7 | myChoiceField.SetValue('Completed');
8 |
9 | // Gets the value, value = 'Completed'
10 | var value = myChoiceField.GetValue();
11 |
12 | // Make the Title field read only
13 | myChoiceField.MakeReadOnly();
14 |
15 | // Hide the field
16 | myChoiceField.Hide();
17 |
18 | // This is the same for a radio button select field
19 | // The value should be equal to the label displayed next to the radio button in the UI
20 | SPUtility.GetSPField('Radio Button Choice').SetValue('Green');
21 |
22 |
23 | // Multi-select fields are the same except you can call SetValue multiple times
24 | // For example, to check the Alpha, Charlie, and Echo checkboxes:
25 | var myMultiSelectField = SPUtility.GetSPField('Multiselect Column');
26 | myMultiSelectField.SetValue('Alpha');
27 | myMultiSelectField.SetValue('Charlie');
28 | myMultiSelectField.SetValue('Echo');
29 |
30 | // for fill-in fields, simply pass a value that does not exist in the list of choices
31 | myMultiSelectField.SetValue('Christmas'); // Christmas is not a choice so Fill-in gets set
32 |
33 | // GetValue returns an array of strings
34 | var values = myMultiSelectField.GetValue();
35 | // Value = ["Alpha", "Bravo", "Charlie"]
36 | }}
--------------------------------------------------------------------------------
/WikiFiles/raw/Common SPField functions.codeplexwiki:
--------------------------------------------------------------------------------
1 | !!! SPUtility.js core API
2 |
3 | * *SPUtility.GetSPField(strFieldName)* - Get a field on DispForm, EditForm, or NewForm by the field's display name. Returns an SPField object (see below).
4 | * *SPUtility.GetSPFieldByInternalName(strFieldName)* - Get a field by its internal column name. Returns an SPField object.
5 | * *SPUtility.GetSPFields()* - Get an object containing every field on the page. Field display name is the key and fieldParams is the value. May change in future versions.
6 | * *SPUtility.GetSPFieldsInternal()* - Get an object containing every field on the page. Field internal column name is the key and fieldParams in the value. (added in version 0.14.0)
7 | * *SPUtility.HideSPField(strFieldName)* - Shortcut for hiding a field by display name (faster than GetSPField if you need to hide a ton of fields at once).
8 | * *SPUtility.ShowSPField(strFieldName)* - Shortcut for showing a field by display name (faster than GetSPField if you need to show a ton of fields at once).
9 | * *SPUtility.Setup(settings)* - Configure how SPUtility works. Especially useful for different number formats and/or languages. See [#Setup] below for more information. (added in version 0.14.0)
10 |
11 | {{
12 | // GetSPField - The main function! Get a field on the current page using the field's display name
13 | // Returns a SPField object depending on the field's type (see section below)
14 | var myField = SPUtility.GetSPField('Title');
15 |
16 | // NEW! As of 0.9.1, get field's using their internal column name
17 | myField = SPUtility.GetSPFieldByInternalName('Date_x0020_and_x0020_Time');
18 |
19 | // HideSPField - hide a field
20 | SPUtility.HideSPField('Title');
21 |
22 | // ShowSPField - opposite of Hide
23 | SPUtility.ShowSPField('Title');
24 |
25 | // GetSPFields - get an object containing all the fields on the page
26 | var fields = SPUtility.GetSPFields();
27 | for (fieldName in fields) {
28 | // do something with the field
29 | var field = SPUtility.GetSPField(fieldName);
30 | }
31 | }}
32 | !!! SPFields
33 | These objects are returned from a call to {{SPUtility.GetSPField}}. All fields support the following functions:
34 | * GetValue - Gets the fields value. *
35 | * SetValue - Sets the fields value. *
36 | * GetDescription - Get a field's description (added in version 0.11.0)
37 | * SetDescription - Set a field's description (added in version 0.11.0)
38 | * MakeReadOnly - Gets the value of the field and replaces any controls with a label preventing the user from editing the field
39 | * MakeEditable - The opposite of MakeReadOnly. Makes a field editable again. Does nothing if the field wasn't read only.
40 | * Hide - Hide's the entire field's row from view.
41 | * Show - Show's the field's row.
42 |
43 | Depending on the type of the field (ex: Choice field or a text field), the functions can perform different operations. SPUtility.js attempts to simplify the interface to each field type as much as possible.
44 |
45 | * Refer to each field's page for more field-specific information (see the matrix on the [Documentation] page).
46 |
47 | !!! Common SPField Functions
48 |
49 | These functions work nearly identically for each field type:
50 |
51 | {{
52 | // Get the SPField object
53 | var myField = SPUtility.GetSPField('Title');
54 |
55 | // Make the field read only
56 | myField.MakeReadOnly();
57 |
58 | // Allow the user to edit the field again
59 | myField.MakeEditable();
60 |
61 | // Hide the field
62 | myField.Hide();
63 |
64 | // Show the field again
65 | myField.Show();
66 | }}
67 | !!! Common SPField Properties
68 |
69 | For each field type, multiple properties are set. These make it easier to reference specific field elements. Every field has the following properties set:
70 |
71 | * Name - Display name of the field
72 | * InternalName - Internal column name
73 | * IsRequired - True if the field is required
74 | * Type - SharePoint field type
75 | * Controls - The element containing all the field's controls
76 | * ControlsRow - The parent table row containing the field's controls
77 | * Label - The element containing the column's name
78 | * LabelRow - The parent table row for the column's name
79 | * ReadOnlyLabel - Default is null, until MakeReadOnly is called, then it holds the reference to the read-only span element
80 |
81 | {{
82 | // get the field
83 | var myField = SPUtility.GetSPField('My Generic Field');
84 |
85 | // Controls references a SPAN element containing all the field specific controls (for example a textbox for Single line of Text fields)
86 | myField.Controls;
87 |
88 | // ControlsRow is generally used only on Survey forms. It references the TR element containing the field's controls. It is null otherwise.
89 | myField.ControlsRow;
90 |
91 | // IsRequired is a boolean value for whether or not the field is required.
92 | myField.IsRequired;
93 |
94 | // Label references the element that contains the display name of the field (ex: My Generic Field, the same value you pass to GetSPField).
95 | myField.Label;
96 |
97 | // LabelRow references the TR element containing the label. This is always set for all forms.
98 | myField.LabelRow;
99 |
100 | // Name is a string containing the fields name (ex: My Generic Field).
101 | myField.Name;
102 |
103 | // ReadOnlyLabel references the DIV for the read only label. It is null until MakeReadOnly is called for the first time.
104 | myField.ReadOnlyLabel;
105 |
106 | // Type is a string containing the fields type (ex: SPFieldText).
107 | myField.Type;
108 | }}
109 |
110 | !!! Setup {anchor:Setup}
111 |
112 | Reconfigure SPUtility.js to work with your locale! Here are the default settings which SPUtility.js uses:
113 | {{
114 | {
115 | 'timeFormat': '12HR', // 12HR or 24HR
116 | 'dateSeparator': '/', // separates month/day/year with / or .
117 | 'decimalSeparator': '.', // separates decimal from number
118 | 'thousandsSeparator': ',', // separates thousands in number
119 | 'stringYes': 'Yes', // Text for when boolean field is True
120 | 'stringNo': 'No' // Text for when boolean field is False
121 | }
122 | }}
123 |
124 | The settings are:
125 | * timeFormat - Set the time format to either 12HR or 24HR. When in 12HR mode, dates will be month/day/year. When in 24HR mode, dates will be day/month/year.
126 | * dateSeparator - Set the date separator. Used to separate year from month from day. Ex: 3/10/2015.
127 | * decimalSeparator - Set the decimal separator (usually a period or a comma character) which is used to separate integer from fractional part of a number.
128 | * thousandsSeparator - Set the thousands separator (usually a period or a comma character).
129 | * stringYes - For Yes/No fields, the text to display when the field is in read-only mode and the field is checked.
130 | * stringNo - For Yes/No fields, the text to display when the field is in read-only mode and the field is NOT checked.
131 |
132 | For example, someone in Spain might want to change the settings to:
133 | {{
134 | SPUtility.Setup({
135 | 'timeFormat': '24HR',
136 | 'decimalSeparator': ',',
137 | 'thousandsSeparator': '.',
138 | 'stringYes': 'Si',
139 | });
140 | }}
141 |
142 | !!! Deprecated methods (will be removed in a later release)
143 |
144 | * *SPUtility.GetTimeFormat()* - Gets the time format which is used to format date/time fields. '12HR' (default) or '24HR'. (added in version 0.11.0)
145 | * *SPUtility.SetTimeFormat(format)* - Set the time format to either 12HR or 24HR. When in 12HR mode, dates will be month/day/year. When in 24HR mode, dates will be day/month/year. (added in version 0.11.0)
146 | * *SPUtility.GetDateSeparator()* - Get the date separator. Default is '/'. (added in version 0.11.2)
147 | * *SPUtility.SetDateSeparator(separator)* - Set the date separator. Used to separate year from month from day. Ex: 3/10/2015. (added in version 0.11.2)
148 | * *SPUtility.GetDecimalSeparator()* - Get the decimal separator. Default is a period '.' (added in version 0.13.0)
149 | * *SPUtility.SetDecimalSeparator(separator)* - Set the decimal separator (usually a period or a comma character) which is used to separate integer from fractional part of a number. (added in version 0.13.0)
150 | * *SPUtility.GetThousandsSeparator()* - Get the thousands separator. Default is a comma ',' (added in version 0.13.0)
151 | * *SPUtility.SetThousandsSeparator(separator)* - Set the thousands separator (usually a period or a comma character). (added in version 0.13.0)
152 |
--------------------------------------------------------------------------------
/WikiFiles/raw/Content Type fields.codeplexwiki:
--------------------------------------------------------------------------------
1 | !!! Description (as of version 0.9.1)
2 | The Content Type field is a special field that only appears once multiple content types have been enabled on a list.
3 |
4 | !!! Usage
5 |
6 |
7 | {code:javscript}
8 | // On EditForm, a Content Type field is displayed but it won't be available on NewForm
9 | // If you try to get the field on NewForm, an exception will be thrown and then logged below
10 | var field = SPUtility.GetSPField('Content Type');
11 |
12 | // Hide the field
13 | field.Hide();
14 |
15 | // Make the field read only
16 | //field.MakeReadOnly();
17 |
18 | // Set the value using the display name
19 | field.SetValue('Item');
20 |
21 | // ... or the content type ID!
22 | field.SetValue('0x0100DBD234B62463314F8DE3C4AA2635CD51');
23 |
24 | // Setting the value does not force the page postback
25 | // if you want to trigger the postback, use the Dropdown onchange
26 | field.Dropdown.onchange();
27 | {code:javscript}
28 |
29 | Check out a code example here: https://github.com/kitmenke/sputility/blob/master/examples/contenttype.html.
--------------------------------------------------------------------------------
/WikiFiles/raw/Date fields.codeplexwiki:
--------------------------------------------------------------------------------
1 | Note: As of v0.10.0, SPUtility.js supports both the 12 hour format (3/14/2014 1:00 AM) and the 24 hour format (14/03/2014 01:00).
2 |
3 | *Note for those using a 24 hour date format:* By default, SPUtility.js uses the 12 hour date format. You will need to call SetTimeFormat before the rest of your code to use the 24 hour date format:
4 |
5 | SPUtility.SetTimeFormat('24HR');
6 |
7 | If you use a separator other than a "/" for your dates, for example 10.03.2015, then call SetDateSeparator:
8 |
9 | SPUtility.SetDateSeparator('.');
10 |
11 | !!! Date
12 | {{
13 | // Date fields (no time value)
14 | var myDateField = SPUtility.GetSPField('Date Field');
15 |
16 | // Set the year (2010), month (august), day (13)
17 | myDateField.SetValue(2010, 8, 13);
18 |
19 | // GetValue returns a SPDateTimeFieldValue object
20 | // Note: As of 0.9.1, the properties will always be numbers (not strings)
21 | var value = myDateField.GetValue();
22 | // value.Year = 2014
23 | // value.Month = 3
24 | // value.Day = 14
25 | // value.IsTimeIncluded = false
26 | // Note: As of 0.10.0, there is a new TimeFormat property for 12HR or 24HR formats
27 | // value.TimeFormat = '12HR'
28 | // value.toString() => '3/14/2014'
29 | // ----- or ----
30 | // value.TimeFormat = '24HR'
31 | // value.toString() => '14/03/2014'
32 |
33 |
34 | // Make the field read only
35 | myDateField.MakeReadOnly();
36 |
37 | // Hide the field
38 | myDateField.Hide();
39 | }}
40 | !!! Date and Time
41 | {{
42 | // Date & Time field
43 | var myDateTimeField = SPUtility.GetSPField('Date Time Field');
44 |
45 | // Sets the value to 8/13/2010 1:30PM
46 | // Should match the values in the time dropdowns
47 | // Hour Ex: 12 PM or 3 AM
48 | // Time Ex: 00, 25, 35 (increments of 5 from 00 to 55)
49 | // Last two parameters should be strings
50 | myDateTimeField.SetValue(2010, 8, 12, '3 PM', '55');
51 |
52 | // Gets a SPDateTimeFieldValue object
53 | // Note: As of 0.9.1, the properties will always be numbers (not strings)
54 | var value = myDateTimeField.GetValue();
55 | // value.Year = 2010
56 | // value.Month = 8
57 | // value.Day = 12
58 | // value.Hour = 15
59 | // value.Minute = 55
60 | // value.IsTimeIncluded = true
61 | // value.toString() => 8/12/2010 3:55PM
62 |
63 | // Set only the date portion (as of 0.9.1)
64 | myDateTimeField.SetDate(2010, 8, 12);
65 |
66 | // Set only the time portion using numbers or strings! (as of 0.9.1)
67 | myDateTimeField.SetTime(8, 30); // 8:30 AM
68 | myDateTimeField.SetTime(15, 0); // 3:00 PM
69 | myDateTimeField.SetTime('5 PM', '55'); // 5:55 PM
70 |
71 | // Make the field read only
72 | myDateTimeField.MakeReadOnly();
73 |
74 | // Hide the field
75 | myDateTimeField.Hide();
76 | }}
77 | Set a DateTime field to "now":
78 | {{
79 | // default contact date to "today"
80 | var today = new Date();
81 | var hour = today.getHours();
82 | if (hour > 12) {
83 | hour = (hour - 12) + " PM";
84 | } else {
85 | hour += " AM";
86 | }
87 | // round the current minute down to the nearest 5 minutes
88 | var minute = today.getMinutes();
89 | minute = minute - (minute % 5);
90 | SPUtility.GetSPField('Contact Date').SetValue(today.getFullYear(), today.getMonth()+1, today.getDate(), hour, minute);
91 | }}
--------------------------------------------------------------------------------
/WikiFiles/raw/Documentation.html:
--------------------------------------------------------------------------------
1 |
2 |
For instructions on how to install SPUtility.js, see Installation.
3 |
Hello world!
4 |
Here is a complete hello world example:
5 |
<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.2.min.js"></script>
6 | <script src="/[change to your subsite]/SiteAssets/sputility.min.js"></script>
7 | <script>
8 | // wait for the window to load
9 | $(document).ready(function () {
10 | // EXAMPLE: Set the value of the Title field to Hello world!
11 | SPUtility.GetSPField('Title').SetValue('Hello world!');
12 | });
13 | </script>
14 |
You could upload this as a HTML file into your SiteAssets library alongside sputility.min.js (adjust src paths as necessary).
Here is a list of all the supported field tables and the various way they are displayed in SharePoint. SPUtility.js does all the hard work of figuring out to show/hide, get/set values, and make them read only!
As of June 2016, version 0.14.2 is the final release of SPUtility.js and I will no longer be actively maintaining this project. Thank you to everyone who helped make this project a success!
4 |
As always, the code is available on
5 | GitHub so please feel free to fork / modify it yourself.
6 |
Description:
7 |
SPUtility.js is a JavaScript library used to make modifications to SharePoint's list forms (NewForm.aspx and EditForm.aspx in a survey, custom list or library). It works with SharePoint 2007, 2010, and 2013 (including SharePoint Online / Office 365).
Keep in mind that SPUtility.js and documentation are still a work in progress... and that it won't work in every situation. It currently will NOT work with:
To use the library, you can just upload SPUtility.js and dependent files into a document library and put a Content Editor Web Part with some JavaScript code on whichever page you want to modify! Detailed instructions are on the
35 | Installation page.
36 |
See the Documentation for the matrix of supported fields and API documentation. Browse the
37 | Changelog to see the list of updates.
38 |
If you do find something that you would like supported or isn't quite working, please don't hesitate to post a
39 | Discussion.
40 |
Finally, if you use SPUtility.js and like it, tweet at me!
41 | @kitmenke
Before
53 |
54 |
55 | SPUtility.GetSPField('Status').MakeReadOnly();
56 |
57 | After
58 |
59 |
Hide a field from view
60 |
Before
61 |
62 |
63 | SPUtility.GetSPField('% Complete').Hide();
64 |
65 | After
66 |
67 |
68 | See the Documentation for more information.
69 |
--------------------------------------------------------------------------------
/WikiFiles/raw/Home_sputility_assignedto.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/raw/Home_sputility_assignedto.png
--------------------------------------------------------------------------------
/WikiFiles/raw/Home_sputility_assignedto_readonly.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/raw/Home_sputility_assignedto_readonly.png
--------------------------------------------------------------------------------
/WikiFiles/raw/Home_sputility_hide_after.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/raw/Home_sputility_hide_after.png
--------------------------------------------------------------------------------
/WikiFiles/raw/Home_sputility_hide_before.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/raw/Home_sputility_hide_before.png
--------------------------------------------------------------------------------
/WikiFiles/raw/Home_sputility_status.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/raw/Home_sputility_status.png
--------------------------------------------------------------------------------
/WikiFiles/raw/Home_sputility_status_readonly.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/raw/Home_sputility_status_readonly.png
--------------------------------------------------------------------------------
/WikiFiles/raw/Home_sputility_title.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/raw/Home_sputility_title.png
--------------------------------------------------------------------------------
/WikiFiles/raw/Home_sputility_title_readonly.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/raw/Home_sputility_title_readonly.png
--------------------------------------------------------------------------------
/WikiFiles/raw/Installation.codeplexwiki:
--------------------------------------------------------------------------------
1 | ! Installation
2 |
3 | The steps below are targeted towards installing the jQuery version of SPUtility on a SharePoint site.
4 |
5 | *SharePoint 2013 Note:* SPUtility.js will not work with Minimal Download Strategy (MDS) enabled in SharePoint 2013 (if you see start.aspx it is currently enabled). To disable, go to Site Settings -> Manage Site Features -> Deactivate Minimal Download Strategy.
6 |
7 | For more troubleshooting information see [Troubleshooting]
8 |
9 | !! SharePoint 2010 / 2013 / SharePoint Online (Office 365)
10 |
11 | *Step 1:* Download [url:jQuery|http://jquery.com/download/]. Version 1.x is recommend for maximum browser compatibility.
12 | *Step 2:* Download [url:sputility.min.js|https://raw.github.com/kitmenke/sputility/master/dist/sputility.min.js]. For development, you can use [url:sputility.js|https://raw.github.com/kitmenke/sputility/master/dist/sputility.js] instead (uncompressed version for easier debugging).
13 | *Step 3:* Upload both files into a document library in your SharePoint site.
14 | *Step 4:* Create a new HTML file with your SPUtility.js script. For example, [url:helloworld.html|https://raw.github.com/kitmenke/sputility/master/examples/helloworld.html] and upload that to your document library as well.
15 | *Step 5:* Navigate to the list form you want to modify. In the ribbon, click on List then Form Web Parts and choose the form you want to edit (ex: New Form, Edit Form).
16 | [image:2013-form-web-parts.png]
17 | *Step 6:* Add a Content Editor web part to the page.
18 | [image:2013-add-content-editor.png]
19 | *Step 7:* Edit Content Editor's web part properties:
20 | * For Content Link, paste in the URL to your HTML file. Ex: /kitsite/Files/helloworld.html
21 | * Under the Appearance section, you will probably also want to set Chrome Type to None so your end users won't see an empty web part.
22 | [image:2013-content-link.png]
23 | *Step 8:* Click the OK button and then click Stop Editing in the ribbon. You're done!
24 |
25 | Note: *+Do NOT click the Apply button+*, you must click the OK button!
26 |
27 | You should now be able to go back into your form and see "Hello World" populated
28 | [image:2013-title-hello-world.png]
29 |
30 | !! SharePoint 2007
31 |
32 | *Step 1-3:* _Steps are the same as above_
33 |
34 | *Step 4:* Navigate to form (EditForm.aspx or NewForm.aspx)
35 |
36 | You can just create/edit/view any item in the list to get to the right form.
37 |
38 | Alternatively, navigate directly to the page using a direct URL. For example: https://example.sharepoint.com/Lists/Test%20List/NewForm.aspx
39 | https://example.sharepoint.com/Lists/Test%20List/EditForm.aspx
40 | https://example.sharepoint.com/Lists/Test%20List/DispForm.aspx
41 |
42 | *Step 5:* Edit the page
43 |
44 | Click Site Actions -> Edit Page.
45 |
46 | If the Edit Page option is missing, use the ToolPaneView=2 URL parameter. For example, https://example.sharepoint.com/Lists/Test%20List/EditForm.aspx?ToolPaneView=2)
47 |
48 | *Step 6:* Add a Content Editor Web Part to the page
49 |
50 | *Step 7:* Edit the web part. Click Edit -> Modify shared web part
51 |
52 | *Step 8:* Edit the content editor's HTML to add some JavaScript. Click Source Editor and paste in your code. For example, you can paste the contents of [url:helloworld.html|https://raw.github.com/kitmenke/sputility/master/examples/helloworld.html] into your content editor.
53 |
54 | *Step 9:* You're done! Save the page / stop editing.
55 |
56 | !!! Alternative Installation Options
57 |
58 | If you don't want to add a content editor to each form, you can also edit the pages using SharePoint Designer and include your scripts that way. This is not recommended unless you are already customizing the page for a different reason.
59 |
60 | !!! Advanced Options for Running SPUtility.js
61 |
62 | !!!! After the whole page has loaded (SharePoint)
63 |
64 | You can use a SharePoint JavaScript function to run your code:
65 | {{
66 | function MyCustomExecuteFunction()
67 | {
68 | // your code here...
69 | }
70 | _spBodyOnLoadFunctionNames.push("MyCustomExecuteFunction");
71 | }}
72 |
73 | !!!! After the whole page has loaded (jQuery)
74 |
75 | You can use jQuery to wait until the entire page has loaded:
76 | {{
77 | $(window).load(function () {
78 | // your code here...
79 | });
80 | }}
81 |
82 | !!!! Before the entire page is loaded, when the DOM is ready (jQuery)
83 |
84 | A slightly faster option, is using $(document).ready(..). This executes as soon as the DOM is ready (before the window loads). [url:http://learn.jquery.com/using-jquery-core/document-ready/].
85 | {{
86 | $(document).ready(function() {
87 | // your code here...
88 | });
89 | }}
90 |
91 | !!!! Immediately after your form is loaded
92 |
93 | This is the fastest and most advanced method.
94 |
95 | If you have a lot of JavaScript code, you may notice the page changing after it loads (as SPUtility works its magic). If you don't want users to see this, you can do the following:
96 | # Move your Content Editor Web Part below the form (it must be *below* the List View Web Part)
97 | # Put your code directly in between the script tags:
98 | {{
99 |
102 | }}
103 | This will force your JavaScript to run immediately. If you don't put the Content Editor below the form, the JavaScript will load before the form has loaded and you will get JavaScript errors.
--------------------------------------------------------------------------------
/WikiFiles/raw/Installation_2013-add-content-editor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/raw/Installation_2013-add-content-editor.png
--------------------------------------------------------------------------------
/WikiFiles/raw/Installation_2013-content-link.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/raw/Installation_2013-content-link.png
--------------------------------------------------------------------------------
/WikiFiles/raw/Installation_2013-form-web-parts.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/raw/Installation_2013-form-web-parts.png
--------------------------------------------------------------------------------
/WikiFiles/raw/Installation_2013-title-hello-world.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/raw/Installation_2013-title-hello-world.png
--------------------------------------------------------------------------------
/WikiFiles/raw/Installation_sp2010-default-edit-form.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/raw/Installation_sp2010-default-edit-form.PNG
--------------------------------------------------------------------------------
/WikiFiles/raw/Lookup fields.codeplexwiki:
--------------------------------------------------------------------------------
1 | !!! Description
2 | Lookup fields display in three modes depending on list settings and the number of lookup items:
3 |
4 | * Small single select lookup
5 | * Large single select lookup
6 | * Multi select lookup
7 |
8 | !!! Usage
9 |
10 | See [Common SPField functions] for generic functions and properties.
11 |
12 | !!!! Small single select lookup
13 | This field displays as a dropdown using a SELECT when allow multiple values = No and there are less than 20 values in the lookup list.
14 |
15 | {{
16 | // get the field
17 | var smallLookup = SPUtility.GetSPField('Small Lookup');
18 |
19 | // set the value using the lookup list item's ID
20 | smallLookup.SetValue(6);
21 |
22 | // set the value using the text
23 | smallLookup.SetValue('Indigo');
24 |
25 | // Gets the dropdown's text value as a string (Ex: Indigo)
26 | var value = smallLookup.GetValue();
27 | }}This field has the Dropdown property set:
28 | {{
29 | var smallLookup = SPUtility.GetSPField('Small Lookup');
30 |
31 | // Dropdown references the SELECT element for the field.
32 | smallLookup.Dropdown;
33 | }}
34 | !!!! Large single select lookup
35 | This field displays as an autocomplete using a text INPUT box when Allow multiple values = No, there are 20 or more values, and your browser is Internet Explorer. If a different browser is used, the field displays as a dropdown (will work like a small single select lookup).
36 |
37 | {{
38 | // get the field
39 | var largeLookup = SPUtility.GetSPField('Large Lookup');
40 |
41 | // set the value using the lookup list item's ID
42 | largeLookup.SetValue(24);
43 |
44 | // set the value using the text
45 | largeLookup.SetValue('Xray');
46 |
47 | // Gets the textbox's value as a string (Ex: Xray)
48 | var value = smallLookup.GetValue();
49 | }}This field has the Textbox property set:
50 | {{
51 | var largeLookup = SPUtility.GetSPField('Large Lookup');
52 |
53 | // Textbox references the autocomplete INPUT element for the field.
54 | largeLookup.Textbox;
55 | }}
56 | !!!! Multi-select lookup
57 | This field displays as two list boxes with Add and Remove buttons when Allow multiple values = Yes.
58 |
59 | {{
60 | // get the field
61 | var multiLookup = SPUtility.GetSPField('Multi-select Lookup');
62 |
63 | // set the value using the lookup list item's ID
64 | multiLookup.SetValue(7);
65 |
66 | // set the value using the text
67 | multiLookup.SetValue('Violet');
68 |
69 | // to remove a value, add an additional parameter
70 | multiLookup.SetValue(7, false);
71 | multiLookup.SetValue('Violet', false);
72 |
73 | // Gets the currently selected values as an array of strings (ex: [ 'Violet', 'Orange' ])
74 | var value = smallLookup.GetValue();
75 | }}This field has four additional properties set:
76 | {{
77 | var largeLookup = SPUtility.GetSPField('Large Lookup');
78 |
79 | // ListChoices references the SELECT element of values that can be added
80 | largeLookup.ListChoices;
81 |
82 | // ListSelections references the SELECT element of values that can be removed (the current selections)
83 | largeLookup.ListSelections;
84 |
85 | // ButtonAdd references the BUTTON element to add items
86 | largeLookup.ButtonAdd;
87 |
88 | // ButtonRemove references the BUTTON element to remove items
89 | largeLookup.ButtonRemove;
90 | }}
91 |
--------------------------------------------------------------------------------
/WikiFiles/raw/People fields.codeplexwiki:
--------------------------------------------------------------------------------
1 | !!! People or Group
2 |
3 | Note 5/8/2014: SetValue is not working in SharePoint 2007. Mostly working in SharePoint 2013 but still seems to have issues.
4 |
5 | SetValue sets the field's inputs and then simulates a click on the "Check Names" button. It does NOT do any sort of validation, so using a user's account name is recommended. Also, you may notice a slight delay when setting the value; this is caused by the Check Names button validating the input.
6 |
7 | {{
8 | // Get the field
9 | var peopleField = SPUtility.GetSPField('Assigned To');
10 |
11 | // Set the field's value
12 | // The value can be either of the following:
13 | // 1. The user's account name
14 | // Don't forget to escape your backslash!
15 | peopleField.SetValue('domain\\myuserid');
16 | // 2. The user's EXACT display name (if it isn't exact then it won't work!)
17 | peopleField.SetValue('Menke, Kit');
18 | // You can use the display name method for groups (if it is enabled for your field)
19 | peopleField.SetValue('Approvers');
20 |
21 | // For multi-select fields, separate your values using semicolons (for people or groups):
22 | peopleField.SetValue('Approvers;Designers');
23 |
24 | // Gets the value of the people field
25 | var value = peopleField.GetValue();
26 |
27 | // Make the people field read only
28 | peopleField.MakeReadOnly();
29 |
30 | // Allow the user to edit the field again
31 | peopleField.MakeEditable();
32 |
33 | // Hide the field
34 | peopleField.Hide();
35 | }}
--------------------------------------------------------------------------------
/WikiFiles/raw/Text fields.codeplexwiki:
--------------------------------------------------------------------------------
1 | !!! Description
2 | Text fields are displayed as a textbox. They work similarly for each of these types:
3 |
4 | * Single line of text
5 | * Number
6 | * Currency
7 | * SPFieldFile (Document library "Name" field)
8 |
9 | !!! Usage
10 |
11 | See [Common SPField functions] for generic functions and properties.
12 |
13 | !!!! Single line of text
14 | {{
15 | var field = SPUtility.GetSPField('Title');
16 | field.SetValue('Hello world!');
17 |
18 | // GetValue returns a string
19 | var value = field.GetValue();
20 | }}
21 | !!!! Number
22 | {{
23 | var field = SPUtility.GetSPField('Number Field');
24 | field.SetValue(42);
25 |
26 | // GetValue returns a number
27 | var value = field.GetValue();
28 | }}
29 | !!!! Currency
30 | {{
31 | var field = SPUtility.GetSPField('Currency Field');
32 | field.SetValue('$97.95');
33 |
34 | // GetValue returns a number (ex: 97.95)
35 | var value = field.GetValue();
36 |
37 | // GetFormattedValue returns a formatted string (ex: $97.95)
38 | value = field.GetFormattedValue();
39 | }}
40 | !!!! SPFieldFile (Document library "Name" field)
41 | {{
42 | var field = SPUtility.GetSPField('Name');
43 | field.SetValue('My Document Name');
44 |
45 | // GetValue returns a string
46 | var value = field.GetValue();
47 | }}
--------------------------------------------------------------------------------
/WikiFiles/raw/Troubleshooting.codeplexwiki:
--------------------------------------------------------------------------------
1 | The most common problems people encounter are during installation.
2 |
3 | ! Check to make sure SPUtility.js and jQuery are being loaded
4 |
5 | Any code you write is dependent on the jQuery and SPUtility libraries being loaded on the page. If they aren't, your code won't work and you'll get an error.
6 |
7 | Symptoms:
8 | * Uncaught ReferenceError: SPUtility is not defined
9 | * Uncaught ReferenceError: jQuery is not defined
10 |
11 | # Navigate to your form. For NewForm.aspx click the New Item button. For EditForm.aspx, create an item in your list and then edit it by clicking the "..." and choosing Edit.
12 | # Press F12 in your browser to bring up the Developer Tools
13 | # Go to the Console tab
14 | # Type in "jQuery"
15 |
16 | If it works, you'll get a function returned in the console: function (a,b){return new m.fn.init(a,b)}
17 |
18 | Good:
19 | [image:sputility-chrome-console.png]
20 |
21 | Bad:
22 | [image:sputility-chrome-console-bad.png]
23 |
24 | ! +SharePoint 2013:+ Disable Minimal Download Strategy (MDS)
25 |
26 | If you see "/_layouts/15/start.aspx" in the URL of your SharePoint site, it is currently enabled. Before you disable MDS, you need to consider whether or not you need it enabled. Unfortunately, I haven't been able to get SPUtility.js to work with it (if you have a solution let me know!).
27 |
28 | What is MDS? Check out [url:https://msdn.microsoft.com/en-us/library/office/dn456544.aspx]
29 |
30 | To disable, go to Site Settings -> Manage Site Features -> Deactivate Minimal Download Strategy. This is a per-site setting so you will need to disable it on any site which you are planning to use SPUtility.js on.
--------------------------------------------------------------------------------
/WikiFiles/raw/Troubleshooting_sputility-chrome-console-bad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/raw/Troubleshooting_sputility-chrome-console-bad.png
--------------------------------------------------------------------------------
/WikiFiles/raw/Troubleshooting_sputility-chrome-console.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/WikiFiles/raw/Troubleshooting_sputility-chrome-console.png
--------------------------------------------------------------------------------
/WikiFiles/raw/URL Fields.codeplexwiki:
--------------------------------------------------------------------------------
1 | !!! Hyperlink
2 | {{
3 | // Get the hyperlink field
4 | var hyperlinkField = SPUtility.GetSPField('Hyperlink Field');
5 |
6 | // Set the field to link (shamelessly) to SPUtility.js on codeplex
7 | hyperlinkField.SetValue('http://sputility.codeplex.com', 'SPUtility.js');
8 |
9 | // Gets the value of the hyperlink field as an array
10 | var values = hyperlinkField.GetValue();
11 | // values[0] = 'http://sputility.codeplex.com'
12 | // values[1] = 'SPUtility.js'
13 |
14 | // Make the hyperlink field read only, displays as a clickable hyperlink
15 | hyperlinkField.MakeReadOnly();
16 | // also there is the ability to display the text only (no hyperlink)
17 | // will display as "http://sputility.codeplex.com, SPUtility.js"
18 | hyperlinkField.MakeReadOnly( { TextOnly: true } );
19 |
20 | // Hide the field
21 | hyperlinkField.Hide();
22 | }}
--------------------------------------------------------------------------------
/WikiFiles/raw/Yes_No fields.codeplexwiki:
--------------------------------------------------------------------------------
1 | !!! Yes/No (boolean)
2 | {{
3 | // Get the "Is important?" field
4 | var myBoolField = SPUtility.GetSPField('Is important?');
5 |
6 | // Set the field to "yes" (checked)
7 | myBoolField.SetValue(true);
8 | // Set the field to "no" (not checked)
9 | myBoolField.SetValue(false);
10 |
11 | // Get the value: true or false
12 | var value = myBoolField.GetValue();
13 |
14 | // Make the field read only
15 | myBoolField.MakeReadOnly();
16 |
17 | // Allow the user to edit the field again
18 | myBoolField.MakeEditable();
19 |
20 | // Hide the field
21 | myBoolField.Hide();
22 | }}
--------------------------------------------------------------------------------
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "sputility",
3 | "description": "A JavaScript library used to make modifications to SharePoint's list forms (NewForm.aspx and EditForm.aspx in a survey, custom list or library).",
4 | "main": "src/sputility.js",
5 | "authors": [
6 | "Kit Menke"
7 | ],
8 | "license": "MIT",
9 | "keywords": [
10 | "sharepoint",
11 | "utility"
12 | ],
13 | "homepage": "https://github.com/kitmenke/sputility",
14 | "moduleType": [ "globals" ],
15 | "devDependencies": {
16 | "grunt-contrib-jshint": "1.0.x",
17 | "grunt-contrib-qunit": "1.0.x",
18 | "grunt-contrib-concat": "1.0.x",
19 | "grunt-contrib-uglify": "0.11.x",
20 | "grunt-contrib-watch": "~0.6.1",
21 | "grunt-contrib-clean": "1.0.x",
22 | "grunt": "0.4.x"
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/examples/contenttype.html:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/examples/dependentfields.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 | SPUtility.js: Dependent fields
13 |
14 |
15 |
16 |
17 |
18 |
19 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |