├── .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).

15 |

SPUtility.js API

16 |

For general usage information, see 17 | functions and properties common to all fields (regardless of type)

18 |

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!

19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 43 | 44 | 47 | 48 | 49 | 50 | 53 | 54 | 55 | 56 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 120 | 121 | 122 | 123 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 |
TypeSP TypeField ConfigurationSupported?
All Field Types Documentation   
Single line of textSPFieldText Yes
41 |

Multiple lines of text

42 |
SPFieldNote 45 |

Plain text

46 |
Yes
51 |

Rich text (Bold, italics, text alignment)

52 |
Yes
57 |

Enhanced rich text (Rich text with pictures, tables, and hyperlinks)

58 |
Yes
Choice (menu to choose from)SPFieldChoiceDrop-Down MenuYes
Drop-Down Menu with fill in valueYes
Radio ButtonsYes
Radio Buttons with fill in valueYes
SPFieldMultiChoiceCheckboxes (allow multiple selections)Yes
Checkboxes (allow multiple selections) with fill in valueYes
Number (1, 1.0, 100)SPFieldNumber Yes
Content Type (as of v0.9.1)ContentTypeChoice  
Currency ($, ¥, €)SPFieldCurrency Yes
Date and TimeSPFieldDateTimeDate OnlyYes
Date & Time
Lookup (information already on this site)SPFieldLookupAllow multiple values = No
119 | Less than 20 values in the lookup list, displays as a dropdown using a SELECT.
Yes
Allow multiple values = No
124 | If 20 or more values, displays as an autocomplete using a text INPUT.
Yes
SPFieldLookupMultiAllow multiple values = Yes (displays as two list boxes)Yes
Yes/No (check box)SPFieldBooleanN/AYes
Person or GroupSPFieldUserAllow multiple selections: NoYes
SPFieldUserMultiAllow multiple selections: YesYes
Hyperlink or PictureSPFieldURL Yes
Name column in a Document LibrarySPFieldFile Yes
Rating Scale (a matrix of choices or a Likert scale)SPFieldGridChoice No
All Day EventSPFieldAllDayEventCalendar field. Checking the box causes a page postback and changes the Start and End Time fields to have a date portion only.No
RecurrenceSPFieldRecurrenceCalendar field. Checking the box causes a page postback in order to display controls to setup Daily/Weekly/Monthly/Yearly recurrence.No
WorkspaceSPFieldCrossProjectLinkSimilar to a yes/no field. Checking yes and then clicking Save will take you to a New Meeting Workspace page.No
Notice a field that isn't listed? Let me know!   
193 |

Tested with SharePoint 2007 and the field types above. Untested with other field types.

194 |

 

195 |

Useful links:

196 | 199 |
-------------------------------------------------------------------------------- /WikiFiles/docs/Home.html: -------------------------------------------------------------------------------- 1 |
2 |

Final release of SPUtility.js (v0.14.2)

3 |

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).

8 |

SPUtility.GetSPField('Title').SetValue('Hello world!');
9 |
10 | 144458

11 |


12 | Download the latest from GitHub!!

13 | 17 |

Features:

18 | 21 |

This can be used for:

22 |
    23 |
  1. Preventing a user from selecting a value when an item is initially created (ex: Status must be PENDING when the item is created) 24 |
  2. Hiding fields from a submitter but allowing the field to be edited (or vice versa). 25 |
  3. Auto-populating the form using a URL with query parameters 26 |
  4. Auto-populate a list column with a sequential number 27 |
  5. Hide/Show field on list form based on value from another field 28 |
29 |

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:

30 |
    31 |
  1. External list forms
  2. Forms that have been customized using Infopath
  3. Certain (weird) fields, see the 32 | matrix of supported fields
  4. Sites with Minimal Download Strategy enabled
33 |

Getting Started

34 |

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

42 |

Usage Examples:

43 |

Set a Text field's value

44 |

SPUtility.GetSPField('Title').SetValue('Hello world!');
45 |
46 | 144458

47 |

Set a Text field's value and make it read only

48 |

SPUtility.GetSPField('Title').SetValue('Hello world!').MakeReadOnly();
49 |
50 | 144459

51 |

Make a Choice field read only

52 |

Before
53 | 144471
54 |
55 | SPUtility.GetSPField('Status').MakeReadOnly();
56 |
57 | After
58 | 144468

59 |

Hide a field from view

60 |

Before
61 | 144469
62 |
63 | SPUtility.GetSPField('% Complete').Hide();
64 |
65 | After
66 | 144470
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 | ![](Installation_2013-form-web-parts.png) 17 | **Step 6:** Add a Content Editor web part to the page. 18 | ![](Installation_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 | ![](Installation_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 | ![](Installation_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 [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 | ![](Troubleshooting_sputility-chrome-console.png) 20 | 21 | Bad: 22 | ![](Troubleshooting_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 [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).

15 |

SPUtility.js API

16 |

For general usage information, see 17 | functions and properties common to all fields (regardless of type)

18 |

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!

19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 43 | 44 | 47 | 48 | 49 | 50 | 53 | 54 | 55 | 56 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 120 | 121 | 122 | 123 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 |
TypeSP TypeField ConfigurationSupported?
All Field Types Documentation   
Single line of textSPFieldText Yes
41 |

Multiple lines of text

42 |
SPFieldNote 45 |

Plain text

46 |
Yes
51 |

Rich text (Bold, italics, text alignment)

52 |
Yes
57 |

Enhanced rich text (Rich text with pictures, tables, and hyperlinks)

58 |
Yes
Choice (menu to choose from)SPFieldChoiceDrop-Down MenuYes
Drop-Down Menu with fill in valueYes
Radio ButtonsYes
Radio Buttons with fill in valueYes
SPFieldMultiChoiceCheckboxes (allow multiple selections)Yes
Checkboxes (allow multiple selections) with fill in valueYes
Number (1, 1.0, 100)SPFieldNumber Yes
Content Type (as of v0.9.1)ContentTypeChoice  
Currency ($, ¥, €)SPFieldCurrency Yes
Date and TimeSPFieldDateTimeDate OnlyYes
Date & Time
Lookup (information already on this site)SPFieldLookupAllow multiple values = No
119 | Less than 20 values in the lookup list, displays as a dropdown using a SELECT.
Yes
Allow multiple values = No
124 | If 20 or more values, displays as an autocomplete using a text INPUT.
Yes
SPFieldLookupMultiAllow multiple values = Yes (displays as two list boxes)Yes
Yes/No (check box)SPFieldBooleanN/AYes
Person or GroupSPFieldUserAllow multiple selections: NoYes
SPFieldUserMultiAllow multiple selections: YesYes
Hyperlink or PictureSPFieldURL Yes
Name column in a Document LibrarySPFieldFile Yes
Rating Scale (a matrix of choices or a Likert scale)SPFieldGridChoice No
All Day EventSPFieldAllDayEventCalendar field. Checking the box causes a page postback and changes the Start and End Time fields to have a date portion only.No
RecurrenceSPFieldRecurrenceCalendar field. Checking the box causes a page postback in order to display controls to setup Daily/Weekly/Monthly/Yearly recurrence.No
WorkspaceSPFieldCrossProjectLinkSimilar to a yes/no field. Checking yes and then clicking Save will take you to a New Meeting Workspace page.No
Notice a field that isn't listed? Let me know!   
193 |

Tested with SharePoint 2007 and the field types above. Untested with other field types.

194 |

 

195 |

Useful links:

196 | 199 |
-------------------------------------------------------------------------------- /WikiFiles/raw/Home.html: -------------------------------------------------------------------------------- 1 |
2 |

Final release of SPUtility.js (v0.14.2)

3 |

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).

8 |

SPUtility.GetSPField('Title').SetValue('Hello world!');
9 |
10 | 144458

11 |


12 | Download the latest from GitHub!!

13 | 17 |

Features:

18 | 21 |

This can be used for:

22 |
    23 |
  1. Preventing a user from selecting a value when an item is initially created (ex: Status must be PENDING when the item is created) 24 |
  2. Hiding fields from a submitter but allowing the field to be edited (or vice versa). 25 |
  3. Auto-populating the form using a URL with query parameters 26 |
  4. Auto-populate a list column with a sequential number 27 |
  5. Hide/Show field on list form based on value from another field 28 |
29 |

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:

30 |
    31 |
  1. External list forms
  2. Forms that have been customized using Infopath
  3. Certain (weird) fields, see the 32 | matrix of supported fields
  4. Sites with Minimal Download Strategy enabled
33 |

Getting Started

34 |

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

42 |

Usage Examples:

43 |

Set a Text field's value

44 |

SPUtility.GetSPField('Title').SetValue('Hello world!');
45 |
46 | 144458

47 |

Set a Text field's value and make it read only

48 |

SPUtility.GetSPField('Title').SetValue('Hello world!').MakeReadOnly();
49 |
50 | 144459

51 |

Make a Choice field read only

52 |

Before
53 | 144471
54 |
55 | SPUtility.GetSPField('Status').MakeReadOnly();
56 |
57 | After
58 | 144468

59 |

Hide a field from view

60 |

Before
61 | 144469
62 |
63 | SPUtility.GetSPField('% Complete').Hide();
64 |
65 | After
66 | 144470
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 | 46 | 47 | 48 | 49 | 50 | 53 | 63 | 64 | 65 | 66 | 69 | 83 | 84 | 85 | 86 | 89 | 99 | 100 | 101 | 102 | 105 | 115 | 116 | 117 | 118 | 121 | 131 | 132 | 133 | 134 | 137 | 147 | 148 | 149 |
51 | Title * 52 | 54 | 58 |
59 | 60 | 61 | 62 |
67 | Do you want cake? 68 | 70 | 74 | 75 |
79 | 80 | 81 | 82 |
87 | Do you want ice cream with your cake? 88 | 90 | 94 |
95 | 96 | 97 | 98 |
103 | Do you want a donut? 104 | 106 | 110 |
111 | 112 | 113 | 114 |
119 | Do you want chocolate ice cream? 120 | 122 | 126 |
127 | 128 | 129 | 130 |
135 | Do you want vanilla ice cream? 136 | 138 | 142 |
143 | 144 | 145 | 146 |
150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /examples/dispform.html: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /examples/dropdownchange.html: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /examples/gettingstarted.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | 26 | 27 | 28 | 31 | 34 | 37 | 40 | 45 | 46 | -------------------------------------------------------------------------------- /examples/helloworld.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /examples/showhidedependentfield.html: -------------------------------------------------------------------------------- 1 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /examples/sputilitytree.js: -------------------------------------------------------------------------------- 1 | function SPUtilityTreeNode(parent, name, value) { 2 | // parent node (SPUtilityTreeNode) 3 | this.parent = parent; 4 | // field's display name, used to get SPField 5 | this.name = name; 6 | // show this node when the value here matches the parent field's value 7 | this.value = value; 8 | // SPUtility.js SPField class 9 | this.field = SPUtility.GetSPField(name); 10 | // array of dependent nodes (SPUtilityTreeNode) 11 | this.childNodes = []; 12 | // callback function which shows or hides dependent fields 13 | this.callback = this._showOrHideFieldsCallback.bind(this); 14 | // schedule callback for when they change the field 15 | // TODO: only works for dropdown fields right now 16 | $(this.field.Dropdown).change(this.callback); 17 | } 18 | SPUtilityTreeNode.prototype._hideNodeAndChildren = function (node) { 19 | // when field is hidden, hide all dependent children as well 20 | node.field.Hide(); 21 | for (var i = 0; i < node.childNodes.length; i++) { 22 | // recurse down the tree to hide all children 23 | this._hideNodeAndChildren(node.childNodes[i]); 24 | } 25 | }; 26 | SPUtilityTreeNode.prototype._showNodeAndChildren = function (node) { 27 | // when field is visible, re-evaluate all the children 28 | // to determine whether to Show or Hide them 29 | node.field.Show(); 30 | node.callback(); 31 | }; 32 | SPUtilityTreeNode.prototype._getOrCreateChild = function (name, value) { 33 | for (var i = 0; i < this.childNodes.length; i++) { 34 | if (this.childNodes[i].name === name && this.childNodes[i].value === value) { 35 | // found matching child node 36 | return this.childNodes[i]; 37 | } 38 | } 39 | var newNode = new SPUtilityTreeNode(this, name, value); 40 | this.childNodes.push(newNode); 41 | return newNode; 42 | }; 43 | SPUtilityTreeNode.prototype._showOrHideFieldsCallback = function () { 44 | var value = this.field.GetValue(); 45 | // go through each dependent child node 46 | // and show/hide it based on the field's value 47 | for (var i = 0; i < this.childNodes.length; i++) { 48 | if (this.childNodes[i].value === value) { 49 | this._showNodeAndChildren(this.childNodes[i]); 50 | } else { 51 | this._hideNodeAndChildren(this.childNodes[i]); 52 | } 53 | } 54 | }; 55 | SPUtilityTreeNode.prototype.addChildNode = function (name, value) { 56 | var childNode = this._getOrCreateChild(name, value); 57 | }; 58 | function SPUtilityTree(name) { 59 | this.root = new SPUtilityTreeNode(null, name); 60 | this.currentNode = null; 61 | this.currentValue = null; 62 | } 63 | SPUtilityTree.prototype._findNode = function (node, searchName) { 64 | if (node.name === searchName) { 65 | return node; 66 | } 67 | // search the children 68 | for (var i = 0; i < node.childNodes.length; i++) { 69 | var foundNode = this._findNode(node.childNodes[i], searchName); 70 | if (foundNode !== null) { 71 | return foundNode; 72 | } 73 | } 74 | return null; 75 | }; 76 | // select a node in the tree 77 | SPUtilityTree.prototype.whenField = function (fieldName) { 78 | // reset currentNode before searching 79 | this.currentNode = this._findNode(this.root, fieldName); 80 | if (this.currentNode === null) { 81 | console.log('ERROR: Field ' + fieldName + ' was not found in the tree!'); 82 | } 83 | return this; 84 | }; 85 | 86 | SPUtilityTree.prototype.hasValue = function (fieldValue) { 87 | this.currentValue = null; 88 | if (this.currentNode === null) { 89 | console.log('ERROR: Current node is not set, call whenField first.'); 90 | return this; 91 | } 92 | this.currentValue = fieldValue; 93 | return this; 94 | }; 95 | 96 | SPUtilityTree.prototype.showFields = function (fieldNames, fieldValue) { 97 | // add a dependent child node 98 | for (var i = 0; i < fieldNames.length; i++) { 99 | this.currentNode.addChildNode(fieldNames[i], this.currentValue); 100 | } 101 | }; 102 | SPUtilityTree.prototype.print = function (str, node, level) { 103 | var spacing = ''; 104 | for (var i = 0; i < level; i++) { 105 | spacing += " " 106 | } 107 | str += spacing + level + ') ' + node.name + '\n'; 108 | for (var i = 0; i < node.childNodes.length; i++) { 109 | str = this.print(str, node.childNodes[i], level+1); 110 | } 111 | return str; 112 | }; 113 | SPUtilityTree.prototype._executeCallbacks = function (node) { 114 | if (node.callback !== null) { 115 | node.callback(); 116 | } 117 | for (var i = 0; i < node.childNodes.length; i++) { 118 | this._executeCallbacks(node.childNodes[i]); 119 | } 120 | }; 121 | SPUtilityTree.prototype.build = function () { 122 | console.log("Building tree..."); 123 | console.log(this.print('', this.root, 0)); 124 | console.log("Executing callbacks...") 125 | this._executeCallbacks(this.root); 126 | }; 127 | -------------------------------------------------------------------------------- /examples/text-depends-on-checkbox.html: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /libs/jquery-loader.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | // Default to the local version. 3 | var path = '../libs/jquery/jquery.js'; 4 | // Get any jquery=___ param from the query string. 5 | var jqversion = location.search.match(/[?&]jquery=(.*?)(?=&|$)/); 6 | // If a version was specified, use that version from code.jquery.com. 7 | if (jqversion) { 8 | path = 'http://code.jquery.com/jquery-' + jqversion[1] + '.js'; 9 | } 10 | // This is the only time I'll ever use document.write, I promise! 11 | document.write(''); 12 | }()); 13 | -------------------------------------------------------------------------------- /libs/qunit/qunit.css: -------------------------------------------------------------------------------- 1 | /** 2 | * QUnit v1.11.0 - A JavaScript Unit Testing Framework 3 | * 4 | * http://qunitjs.com 5 | * 6 | * Copyright 2012 jQuery Foundation and other contributors 7 | * Released under the MIT license. 8 | * http://jquery.org/license 9 | */ 10 | 11 | /** Font Family and Sizes */ 12 | 13 | #qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult { 14 | font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif; 15 | } 16 | 17 | #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; } 18 | #qunit-tests { font-size: smaller; } 19 | 20 | 21 | /** Resets */ 22 | 23 | #qunit-tests, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter { 24 | margin: 0; 25 | padding: 0; 26 | } 27 | 28 | 29 | /** Header */ 30 | 31 | #qunit-header { 32 | padding: 0.5em 0 0.5em 1em; 33 | 34 | color: #8699a4; 35 | background-color: #0d3349; 36 | 37 | font-size: 1.5em; 38 | line-height: 1em; 39 | font-weight: normal; 40 | 41 | border-radius: 5px 5px 0 0; 42 | -moz-border-radius: 5px 5px 0 0; 43 | -webkit-border-top-right-radius: 5px; 44 | -webkit-border-top-left-radius: 5px; 45 | } 46 | 47 | #qunit-header a { 48 | text-decoration: none; 49 | color: #c2ccd1; 50 | } 51 | 52 | #qunit-header a:hover, 53 | #qunit-header a:focus { 54 | color: #fff; 55 | } 56 | 57 | #qunit-testrunner-toolbar label { 58 | display: inline-block; 59 | padding: 0 .5em 0 .1em; 60 | } 61 | 62 | #qunit-banner { 63 | height: 5px; 64 | } 65 | 66 | #qunit-testrunner-toolbar { 67 | padding: 0.5em 0 0.5em 2em; 68 | color: #5E740B; 69 | background-color: #eee; 70 | overflow: hidden; 71 | } 72 | 73 | #qunit-userAgent { 74 | padding: 0.5em 0 0.5em 2.5em; 75 | background-color: #2b81af; 76 | color: #fff; 77 | text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px; 78 | } 79 | 80 | #qunit-modulefilter-container { 81 | float: right; 82 | } 83 | 84 | /** Tests: Pass/Fail */ 85 | 86 | #qunit-tests { 87 | list-style-position: inside; 88 | } 89 | 90 | #qunit-tests li { 91 | padding: 0.4em 0.5em 0.4em 2.5em; 92 | border-bottom: 1px solid #fff; 93 | list-style-position: inside; 94 | } 95 | 96 | #qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running { 97 | display: none; 98 | } 99 | 100 | #qunit-tests li strong { 101 | cursor: pointer; 102 | } 103 | 104 | #qunit-tests li a { 105 | padding: 0.5em; 106 | color: #c2ccd1; 107 | text-decoration: none; 108 | } 109 | #qunit-tests li a:hover, 110 | #qunit-tests li a:focus { 111 | color: #000; 112 | } 113 | 114 | #qunit-tests li .runtime { 115 | float: right; 116 | font-size: smaller; 117 | } 118 | 119 | .qunit-assert-list { 120 | margin-top: 0.5em; 121 | padding: 0.5em; 122 | 123 | background-color: #fff; 124 | 125 | border-radius: 5px; 126 | -moz-border-radius: 5px; 127 | -webkit-border-radius: 5px; 128 | } 129 | 130 | .qunit-collapsed { 131 | display: none; 132 | } 133 | 134 | #qunit-tests table { 135 | border-collapse: collapse; 136 | margin-top: .2em; 137 | } 138 | 139 | #qunit-tests th { 140 | text-align: right; 141 | vertical-align: top; 142 | padding: 0 .5em 0 0; 143 | } 144 | 145 | #qunit-tests td { 146 | vertical-align: top; 147 | } 148 | 149 | #qunit-tests pre { 150 | margin: 0; 151 | white-space: pre-wrap; 152 | word-wrap: break-word; 153 | } 154 | 155 | #qunit-tests del { 156 | background-color: #e0f2be; 157 | color: #374e0c; 158 | text-decoration: none; 159 | } 160 | 161 | #qunit-tests ins { 162 | background-color: #ffcaca; 163 | color: #500; 164 | text-decoration: none; 165 | } 166 | 167 | /*** Test Counts */ 168 | 169 | #qunit-tests b.counts { color: black; } 170 | #qunit-tests b.passed { color: #5E740B; } 171 | #qunit-tests b.failed { color: #710909; } 172 | 173 | #qunit-tests li li { 174 | padding: 5px; 175 | background-color: #fff; 176 | border-bottom: none; 177 | list-style-position: inside; 178 | } 179 | 180 | /*** Passing Styles */ 181 | 182 | #qunit-tests li li.pass { 183 | color: #3c510c; 184 | background-color: #fff; 185 | border-left: 10px solid #C6E746; 186 | } 187 | 188 | #qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; } 189 | #qunit-tests .pass .test-name { color: #366097; } 190 | 191 | #qunit-tests .pass .test-actual, 192 | #qunit-tests .pass .test-expected { color: #999999; } 193 | 194 | #qunit-banner.qunit-pass { background-color: #C6E746; } 195 | 196 | /*** Failing Styles */ 197 | 198 | #qunit-tests li li.fail { 199 | color: #710909; 200 | background-color: #fff; 201 | border-left: 10px solid #EE5757; 202 | white-space: pre; 203 | } 204 | 205 | #qunit-tests > li:last-child { 206 | border-radius: 0 0 5px 5px; 207 | -moz-border-radius: 0 0 5px 5px; 208 | -webkit-border-bottom-right-radius: 5px; 209 | -webkit-border-bottom-left-radius: 5px; 210 | } 211 | 212 | #qunit-tests .fail { color: #000000; background-color: #EE5757; } 213 | #qunit-tests .fail .test-name, 214 | #qunit-tests .fail .module-name { color: #000000; } 215 | 216 | #qunit-tests .fail .test-actual { color: #EE5757; } 217 | #qunit-tests .fail .test-expected { color: green; } 218 | 219 | #qunit-banner.qunit-fail { background-color: #EE5757; } 220 | 221 | 222 | /** Result */ 223 | 224 | #qunit-testresult { 225 | padding: 0.5em 0.5em 0.5em 2.5em; 226 | 227 | color: #2b81af; 228 | background-color: #D2E0E6; 229 | 230 | border-bottom: 1px solid white; 231 | } 232 | #qunit-testresult .module-name { 233 | font-weight: bold; 234 | } 235 | 236 | /** Fixture */ 237 | 238 | #qunit-fixture { 239 | position: absolute; 240 | top: -10000px; 241 | left: -10000px; 242 | width: 1000px; 243 | height: 1000px; 244 | } 245 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "SPUtility.js", 3 | "version": "0.14.2", 4 | "repository": { 5 | "type": "git", 6 | "url": "git://github.com/kitmenke/sputility.git" 7 | }, 8 | "engines": { 9 | "node": ">= 0.8.0" 10 | }, 11 | "scripts": { 12 | "test": "grunt qunit" 13 | }, 14 | "devDependencies": { 15 | "grunt-contrib-jshint": "1.0.x", 16 | "grunt-contrib-qunit": "1.0.x", 17 | "grunt-contrib-concat": "1.0.x", 18 | "grunt-contrib-uglify": "0.11.x", 19 | "grunt-contrib-watch": "~0.6.1", 20 | "grunt-contrib-clean": "1.0.x", 21 | "grunt": "0.4.x" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /sputility.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sputility", 3 | "title": "SPUtility.js", 4 | "description": "A JavaScript library that is used to alter SharePoint's user interface (mostly NewForm and EditForm).", 5 | "version": "0.14.2", 6 | "homepage": "https://sputility.codeplex.com/", 7 | "author": { 8 | "name": "Kit Menke", 9 | "url": "kitmenke.com" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git://github.com/kitmenke/sputility.git" 14 | }, 15 | "bugs": "https://github.com/kitmenke/sputility/issues", 16 | "licenses": [ 17 | { 18 | "type": "The MIT License (MIT)", 19 | "url": "http://opensource.org/licenses/MIT" 20 | } 21 | ], 22 | "dependencies": { 23 | "jquery": "1.9" 24 | }, 25 | "keywords": [] 26 | } 27 | -------------------------------------------------------------------------------- /src/.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "curly": true, 3 | "eqeqeq": true, 4 | "immed": true, 5 | "latedef": true, 6 | "newcap": false, 7 | "noarg": true, 8 | "sub": true, 9 | "undef": true, 10 | "unused": true, 11 | "boss": true, 12 | "eqnull": true, 13 | "browser": true, 14 | "indent": 3, 15 | "globals": { 16 | "jQuery": false, 17 | "window": false, 18 | "byid": false, 19 | "_spPageContextInfo": false, 20 | "ChangeContentType": false, 21 | "SP": false, 22 | "console": false 23 | }, 24 | "exported": [ "SPUtility" ] 25 | } 26 | -------------------------------------------------------------------------------- /test/.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 | "browser": true, 14 | "predef": [ 15 | "SPUtility", 16 | "jQuery", 17 | "QUnit", 18 | "module", 19 | "test", 20 | "asyncTest", 21 | "expect", 22 | "start", 23 | "stop", 24 | "ok", 25 | "equal", 26 | "notEqual", 27 | "deepEqual", 28 | "notDeepEqual", 29 | "strictEqual", 30 | "notStrictEqual", 31 | "throws" 32 | ] 33 | } -------------------------------------------------------------------------------- /test/img/blank.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/test/img/blank.gif -------------------------------------------------------------------------------- /test/img/calendar.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kitmenke/sputility/68b9091b83eb56371014e031276f9ca35b947278/test/img/calendar.gif -------------------------------------------------------------------------------- /test/integration_test_2013.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 |
8 | -------------------------------------------------------------------------------- /test/test_boolean.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SPUtility.js Yes/No Field Test Suite 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 32 | 42 | 43 | 44 | 45 | 50 | 60 | 61 | 62 | 63 |
28 |

29 | Yes/No 30 |

31 |
33 | 37 | 38 | 39 |
40 |
41 |
46 |

47 | Yes/No2 48 |

49 |
51 | 55 | 56 | 57 |
58 |
59 |
64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /test/test_boolean.js: -------------------------------------------------------------------------------- 1 | /* Tests specific to Yes/No (boolean) fields */ 2 | (function() { 3 | module("SPBooleanField (customizable strings)", { 4 | setup: function() { 5 | SPUtility.Setup({ 6 | 'stringYes': 'Yep', 7 | 'stringNo': 'Nope' 8 | }); 9 | } 10 | }); 11 | 12 | test('MakeReadOnly', function() { 13 | expect(5); 14 | var field = SPUtility.GetSPField('Yes/No'); 15 | strictEqual(typeof field, "object", "GetSPField should have returned an object."); 16 | field.SetValue(false).MakeReadOnly(); 17 | strictEqual(field.ReadOnlyLabel.text(), "Nope", "Setting the value to false should result in Nope."); 18 | field.SetValue(true); 19 | strictEqual(field.ReadOnlyLabel.text(), "Yep", "Setting the value to false should result in Yep."); 20 | field.SetValue('Nope'); 21 | strictEqual(field.ReadOnlyLabel.text(), "Nope", "Setting the value to Nope should result in Nope."); 22 | field.SetValue('Yep'); 23 | strictEqual(field.ReadOnlyLabel.text(), "Yep", "Setting the value to Nope should result in Yep."); 24 | }); 25 | }(jQuery)); 26 | -------------------------------------------------------------------------------- /test/test_dispform.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | module("DispForm"); 3 | 4 | test("The static function IsDispForm is available and working.", function() { 5 | expect(1); 6 | ok(SPUtility.IsDispForm(), "The IsDispForm method should return true."); 7 | }); 8 | }(jQuery)); 9 | -------------------------------------------------------------------------------- /test/test_doclib_dispform_2013.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SPUtility.js Document Library DispForm Tests (SharePoint 2013) 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 113 | 126 | 127 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 45 | 46 | 47 | 48 | 49 | 58 | 59 | 60 | 61 | 62 |
Name 37 | 41 | Test Document.docx 42 | 43 | 44 |
Title 50 | 54 | 55 | 56 | 57 |
63 | 64 | 65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 95 | 96 | 97 | 98 | 99 | 106 | 107 | 108 | 109 | 110 |
111 | 112 |
114 |
115 |
116 |
117 | 122 |
123 |
124 |
125 |
128 | 129 | 130 | 131 | -------------------------------------------------------------------------------- /test/test_doclib_dispform_2013.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | module("DocLib DispForm"); 3 | 4 | // TODO: test file field on dispform 5 | }(jQuery)); 6 | -------------------------------------------------------------------------------- /test/test_field_properties.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 3 | // a generic test to use for each of the different fields 4 | var test_get_object_with_property = function() { 5 | expect(3); 6 | // get the field (should not throw an error) 7 | var spfield = SPUtility.GetSPField(this.spfieldName); 8 | // make sure we got an object 9 | ok(spfield, "GetSPField should return an object."); 10 | // the object has the property we expect 11 | ok(spfield[this.propertyName], "Object should have a property named " + this.propertyName); 12 | /// the property is assigned the correct element 13 | strictEqual(spfield[this.propertyName].id, this.controlId, "Property should be assigned correct element."); 14 | }; 15 | 16 | module("SPTextField", { 17 | setup: function() { 18 | this.controlId = 'ctl00_m_g_b2a76005_5d3d_4591_9f83_b32d5af4e808_ctl00_ctl05_ctl00_ctl00_ctl00_ctl04_ctl00_ctl00_TextField'; 19 | this.propertyName = 'Textbox'; 20 | this.spfieldName = 'Title'; 21 | } 22 | }); 23 | 24 | test("Text fields should have a Textbox property", test_get_object_with_property); 25 | 26 | module("ContentTypeChoice", { 27 | setup: function() { 28 | this.controlId = 'sputility-contenttype'; 29 | this.propertyName = 'Dropdown'; 30 | this.spfieldName = 'Content Type'; 31 | } 32 | }); 33 | 34 | test("Content type fields should have a Dropdown property", test_get_object_with_property); 35 | 36 | module("SPNumberField", { 37 | setup: function() { 38 | this.controlId = 'ctl00_m_g_b2a76005_5d3d_4591_9f83_b32d5af4e808_ctl00_ctl05_ctl08_ctl00_ctl00_ctl04_ctl00_ctl00_TextField'; 39 | this.propertyName = 'Textbox'; 40 | this.spfieldName = 'Number'; 41 | } 42 | }); 43 | 44 | test("Number fields should have a Textbox property", test_get_object_with_property); 45 | 46 | module("SPCurrencyField", { 47 | setup: function() { 48 | this.controlId = 'ctl00_m_g_b2a76005_5d3d_4591_9f83_b32d5af4e808_ctl00_ctl05_ctl09_ctl00_ctl00_ctl04_ctl00_ctl00_TextField'; 49 | this.propertyName = 'Textbox'; 50 | this.spfieldName = 'Currency'; 51 | } 52 | }); 53 | 54 | test("Currency fields should have a Textbox property", test_get_object_with_property); 55 | 56 | module("SPFieldChoice - Dropdown", { 57 | setup: function() { 58 | this.controlId = 'ctl00_m_g_b2a76005_5d3d_4591_9f83_b32d5af4e808_ctl00_ctl05_ctl04_ctl00_ctl00_ctl04_ctl00_DropDownChoice'; 59 | this.propertyName = 'Dropdown'; 60 | this.spfieldName = 'Dropdown Choice'; 61 | } 62 | }); 63 | 64 | test("Dropdown Choice fields should have a Dropdown property", test_get_object_with_property); 65 | 66 | module("SPFieldChoice Dropdown (with fill in)", { 67 | setup: function() { 68 | this.controlId = 'ctl00_m_g_b2a76005_5d3d_4591_9f83_b32d5af4e808_ctl00_ctl05_ctl05_ctl00_ctl00_ctl04_ctl00_DropDownChoice'; 69 | this.propertyName = 'Dropdown'; 70 | this.spfieldName = 'Dropdown Choice with Fill-in'; 71 | } 72 | }); 73 | 74 | test("Dropdown Choice fields should have a Dropdown property", test_get_object_with_property); 75 | 76 | }(jQuery)); 77 | -------------------------------------------------------------------------------- /test/test_list.js: -------------------------------------------------------------------------------- 1 | /* Tests specific to SharePoint lists */ 2 | (function($) { 3 | module("SPFieldDateTime (date and time)"); 4 | 5 | test('Empty date field displays time in read only label #27', function() { 6 | expect(3); 7 | var field = SPUtility.GetSPField('Date and Time2'); 8 | // field has no value set 9 | field.MakeReadOnly(); 10 | strictEqual(field.ReadOnlyLabel.text(), "", "Read only label should be empty string."); 11 | field.SetValue(2013, 8, 15, '8 AM', '30'); 12 | strictEqual(field.ReadOnlyLabel.text(), "8/15/2013 8:30 AM", "Read only label should be 8/15/2013 8:30 AM."); 13 | field.SetValue(); 14 | strictEqual(field.ReadOnlyLabel.text(), "", "Read only label should be empty string."); 15 | }); 16 | 17 | module("SPNumberField"); 18 | 19 | test('Empty numeric field displays as NaN in read only label #28', function() { 20 | expect(3); 21 | var field = SPUtility.GetSPField('NumberEmpty'); 22 | // field has no value set 23 | field.MakeReadOnly(); 24 | strictEqual(field.ReadOnlyLabel.text(), "", "Read only label should be empty string."); 25 | field.SetValue(42); 26 | strictEqual(field.ReadOnlyLabel.text(), "42", "Read only label should be 42."); 27 | field.SetValue(); 28 | strictEqual(field.ReadOnlyLabel.text(), "", "Read only label should be empty string."); 29 | }); 30 | 31 | module("ContentTypeChoice", { 32 | setup: function() { 33 | this.field = SPUtility.GetSPField('Content Type'); 34 | } 35 | }); 36 | 37 | test("Get the field", function() { 38 | expect(2); 39 | notStrictEqual(this.field, null, "GetSPField should have returned an object."); 40 | strictEqual(this.field.Type, "ContentTypeChoice", "The field's type should be " + this.field.Type); 41 | }); 42 | 43 | test("Get and set the value", function() { 44 | expect(1); 45 | 46 | var expected = 'Item'; 47 | this.field.SetValue(expected); 48 | 49 | strictEqual(this.field.GetValue(), 50 | expected, 51 | "SetValue() failed to set Textbox."); 52 | }); 53 | 54 | test("Get and set the value using content type id", function() { 55 | expect(1); 56 | 57 | var expected = 'Schedule and Reservations'; 58 | this.field.SetValue('0x01020072BB2A38F0DB49C3A96CF4FA8552995600C75E64B08FECF44588B8BCA97362240C'); 59 | 60 | strictEqual(this.field.GetValue(), 61 | expected, 62 | "SetValue() failed to set Textbox."); 63 | }); 64 | 65 | test("MakeReadOnly()", function() { 66 | expect(3); 67 | 68 | var expected = 'Reservations'; 69 | this.field.SetValue('0x0102004F51EFDEA49C49668EF9C6744C8CF87D00107B364268BC6A4BB2FC37572DC79248'); 70 | this.field.MakeReadOnly(); 71 | var actual = this.field.ReadOnlyLabel.text(); 72 | 73 | strictEqual(actual, 74 | expected, 75 | "Validate SetValue() updates the read-only label."); 76 | strictEqual($(this.field.Controls).css('display'), "none"); 77 | this.field.MakeEditable(); 78 | ok($(this.field.Controls).css('display') !== "none"); 79 | }); 80 | 81 | module("SPURLField (hyperlink)", { 82 | setup: function() { 83 | this.field = SPUtility.GetSPField('Hyperlink'); 84 | } 85 | }); 86 | 87 | test('GetSPField()', function() { 88 | expect(2); 89 | notStrictEqual(this.field, null, "GetSPField should have returned an object."); 90 | strictEqual(this.field.Type, "SPFieldURL", "The field's type should be " + this.field.Type); 91 | }); 92 | 93 | test("GetValue() and SetValue()", function() { 94 | expect(3); 95 | 96 | var expected = ['http://sputility.codeplex.com', 'SPUtility.js']; 97 | this.field.SetValue(expected[0], expected[1]); 98 | 99 | // make sure both textboxes were set correctly 100 | equal($('#Hyperlink_2ef372e5-47ae-4d20-89dd-5a43e5428ae6_UrlFieldUrl').val(), expected[0]); 101 | equal($('#Hyperlink_2ef372e5-47ae-4d20-89dd-5a43e5428ae6_UrlFieldDescription').val(), expected[1]); 102 | 103 | // Gets the value of the hyperlink field as an array 104 | var actual = this.field.GetValue(); 105 | deepEqual(actual, expected, 106 | "GetValue() should return an array of two strings containing URL and Description."); 107 | }); 108 | 109 | module("SPLookupMultiField", { 110 | setup: function() { 111 | this.field = SPUtility.GetSPField('Multi-Priority Lookup Field'); 112 | } 113 | }); 114 | 115 | test('GetSPField()', function() { 116 | expect(6); 117 | notStrictEqual(this.field, null, "GetSPField should have returned an object."); 118 | strictEqual(this.field.Type, "SPFieldLookupMulti", "Expected type is SPFieldLookupMulti"); 119 | ok(this.field.ListChoices, "Expected to have a property named ListChoices"); 120 | ok(this.field.ListSelections, "Expected to have a property named ListSelections"); 121 | ok(this.field.ButtonAdd, "Expected to have a property named ButtonAdd"); 122 | ok(this.field.ButtonRemove, "Expected to have a property named ButtonRemove"); 123 | }); 124 | 125 | module("SPLookupField (single-select, small lookup)", { 126 | setup: function() { 127 | this.field = SPUtility.GetSPField('Small Lookup'); 128 | } 129 | }); 130 | 131 | test('GetSPField()', function() { 132 | expect(2); 133 | notStrictEqual(this.field, null, "GetSPField should have returned an object."); 134 | strictEqual(this.field.Type, "SPFieldLookup", "The field's type should be " + this.field.Type); 135 | }); 136 | 137 | test("GetValue() and SetValue()", function() { 138 | expect(2); 139 | 140 | var expected = 'Charlie'; 141 | this.field.SetValue(expected); 142 | 143 | // make sure the select was set correctly 144 | equal($('#Small_x0020_Lookup_fc0ce102-b10d-48f1-bdce-760fd008eead_LookupField').val(), '3'); 145 | 146 | var actual = this.field.GetValue(); 147 | strictEqual(actual, expected); 148 | }); 149 | 150 | module("SPLookupField (single-select, big lookup with autocomplete)", { 151 | setup: function() { 152 | this.field = SPUtility.GetSPField('Large Lookup Field'); 153 | } 154 | }); 155 | 156 | test('GetSPField()', function() { 157 | expect(2); 158 | notStrictEqual(this.field, null, "GetSPField should have returned an object."); 159 | strictEqual(this.field.Type, "SPFieldLookup", "The field's type should be " + this.field.Type); 160 | }); 161 | 162 | test("GetValue() and SetValue()", function() { 163 | expect(2); 164 | 165 | var expected = 'Charlie'; 166 | this.field.SetValue(expected); 167 | 168 | // make sure the select was set correctly 169 | equal($('#ctl00_m_g_a94984b1_b613_4db4_8e53_e809e1fc4a0b_ctl00_ctl04_ctl12_ctl00_ctl00_ctl04_ctl00_ctl01').val(), expected); 170 | 171 | var actual = this.field.GetValue(); 172 | strictEqual(actual, expected); 173 | }); 174 | 175 | 176 | module("SPUserField", { 177 | setup: function() { 178 | this.field = SPUtility.GetSPField('Person or Group'); 179 | } 180 | }); 181 | 182 | test('GetSPField()', function() { 183 | expect(2); 184 | notStrictEqual(this.field, null, "GetSPField should have returned an object."); 185 | strictEqual(this.field.Type, "SPFieldUser", "The field's type should be " + this.field.Type); 186 | }); 187 | 188 | /* Unable to test People fields locally 189 | * test("Correct properties are set", function() { 190 | expect(2); 191 | ok(this.field.ClientPeoplePicker, 'ClientPeoplePicker property not set'); 192 | ok(this.field.EditorInput, 'EditorInput property not set'); 193 | });*/ 194 | 195 | module("Miscellaneous tests"); 196 | 197 | test('Splitting autocomplete choices', function() { 198 | expect(1); 199 | 200 | // a list item ID was passed to the function so attempt to lookup the text value 201 | var choices = '(None)|0|A pipe || in the middle|31|AAA BBB CCC|30|Alpha|1|Bravo|2|Charlie|3|Delta|4|Echo|5|Foxtrot|6|Golf|7|Hotel|8|India|9|Juliet|10|Kilo|11|Lima|12|Mike|13|November|14|Oscar|15|Papa|16|Quebec|17|Romeo|18|Sierra|19|Tango|29'; 202 | var expected = [ 203 | "(None)", 204 | "0", 205 | "A pipe || in the middle", 206 | "31", 207 | "AAA BBB CCC", 208 | "30", 209 | "Alpha", 210 | "1", 211 | "Bravo", 212 | "2", 213 | "Charlie", 214 | "3", 215 | "Delta", 216 | "4", 217 | "Echo", 218 | "5", 219 | "Foxtrot", 220 | "6", 221 | "Golf", 222 | "7", 223 | "Hotel", 224 | "8", 225 | "India", 226 | "9", 227 | "Juliet", 228 | "10", 229 | "Kilo", 230 | "11", 231 | "Lima", 232 | "12", 233 | "Mike", 234 | "13", 235 | "November", 236 | "14", 237 | "Oscar", 238 | "15", 239 | "Papa", 240 | "16", 241 | "Quebec", 242 | "17", 243 | "Romeo", 244 | "18", 245 | "Sierra", 246 | "19", 247 | "Tango", 248 | "29" 249 | ]; 250 | 251 | // split the string on every pipe character followed by a digit 252 | choices = choices.split(/\|(?=\d+)/); 253 | var c = [], pipeIndex; 254 | c.push(choices[0]); 255 | for (var i = 1; i < choices.length - 1; i++) { 256 | pipeIndex = choices[i].indexOf('|'); // split on the first pipe only 257 | c.push(choices[i].substring(0, pipeIndex)); 258 | c.push(choices[i].substring(pipeIndex+1)); 259 | } 260 | c.push(choices[choices.length-1]); 261 | 262 | deepEqual(c, expected); 263 | }); 264 | }(jQuery)); 265 | -------------------------------------------------------------------------------- /test/test_list_dispform.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SPUtility.js DispForm Tests 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 40 | 41 | 42 | 43 | 44 | 53 | 54 | 55 | 56 | 57 | 66 | 67 | 68 | 69 | 70 | 79 | 80 | 81 | 82 | 83 | 92 | 93 | 94 | 95 | 96 | 105 | 106 | 107 | 108 | 109 | 118 | 119 | 120 | 121 | 122 | 131 | 132 | 133 | 134 | 135 | 144 | 145 | 146 | 147 | 148 | 157 | 158 | 159 | 160 | 161 | 170 | 171 | 172 | 173 | 174 | 183 | 184 | 185 | 186 | 187 | 196 | 197 | 198 | 199 | 200 | 209 | 210 | 211 | 212 | 213 | 222 | 223 | 224 | 225 | 226 | 235 | 236 | 237 | 238 | 239 | 248 | 249 | 250 | 251 | 252 | 261 | 262 | 263 | 264 | 265 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 290 | 291 | 292 | 293 |
Title 32 | 36 | Alpha 37 | 38 | 39 |
Multi-line Plain Text 45 | 49 |
Alpha hello world
50 | 51 | 52 |
Dropdown Choice 58 | 62 | Alpha 63 | 64 | 65 |
Dropdown Choice with Fill-in 71 | 75 | Alpha 76 | 77 | 78 |
Radio Buttons 84 | 88 | Alpha 89 | 90 | 91 |
Radio Buttons with Fill-in 97 | 101 | Alpha 102 | 103 | 104 |
Checkboxes 110 | 114 | Alpha; Bravo; Charlie 115 | 116 | 117 |
Checkboxes with Fill-in 123 | 127 | Alpha; Bravo; Charlie 128 | 129 | 130 |
Number 136 | 140 | 42 141 | 142 | 143 |
Currency 149 | 153 | $99.95 154 | 155 | 156 |
Date Only 162 | 166 | 3/5/2016  167 | 168 | 169 |
Date and Time 175 | 179 | 3/5/2016 4:45 PM  180 | 181 | 182 |
Yes/No 188 | 192 | No 193 | 194 | 195 |
Hyperlink 201 | 205 | SPUtility.js 206 | 207 | 208 |
Small Lookup 214 | 218 | Alpha 219 | 220 | 221 |
Large Lookup 227 | 231 | Alpha 232 | 233 | 234 |
Multi-value Lookup 240 | 244 | Charlie 245 | 246 | 247 |
Enhanced Rich Text 253 | 257 |

​Hello world

258 | 259 | 260 |
Person or Group 266 | 270 | No presence informationNo presence informationFirstname Lastname 271 | 272 | 273 |
294 |
295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 321 | 322 | 323 | 324 | 325 | 332 | 333 | 334 | 335 | 336 |
337 | 338 | 339 | 340 | -------------------------------------------------------------------------------- /test/test_list_dispform.js: -------------------------------------------------------------------------------- 1 | /* Tests specific to SharePoint lists */ 2 | (function() { 3 | 4 | module("SPDispFormTextField List Fields"); 5 | 6 | /* 7 | * Generic test for SPDispFormTextFields 8 | * These fields should return a normal type, allow GetValue, and 9 | * SetValue. 10 | */ 11 | function dispFormTextFieldTest(fieldName, fieldType, beforeExpected) { 12 | expect(5); 13 | 14 | var expected = 'foo bar', field = SPUtility.GetSPField(fieldName); 15 | notStrictEqual(field, null, "GetSPField should have returned an object."); 16 | strictEqual(field.Type, fieldType, "The field's type should be " + fieldType + "."); 17 | ok(field.TextNode, "The field should have a TextNode property."); 18 | strictEqual(field.GetValue(), beforeExpected, "The field's value should first be " + beforeExpected); 19 | 20 | field.SetValue(expected); 21 | strictEqual(field.GetValue(), 22 | expected, 23 | "SetValue should set the value to 'foo bar'."); 24 | } 25 | 26 | test("Text", function() { dispFormTextFieldTest('Title', 'SPFieldText', 'Alpha'); }); 27 | test("Dropdown Choice", function() { dispFormTextFieldTest('Dropdown Choice', 'SPFieldChoice', 'Alpha'); }); 28 | test("Dropdown Choice with Fill-in", function() { dispFormTextFieldTest('Dropdown Choice with Fill-in', 'SPFieldChoice', 'Alpha'); }); 29 | test("Radio Buttons", function() { dispFormTextFieldTest('Radio Buttons', 'SPFieldChoice', 'Alpha'); }); 30 | test("Radio Buttons with Fill-in", function() { dispFormTextFieldTest('Radio Buttons with Fill-in', 'SPFieldChoice', 'Alpha'); }); 31 | test("Checkboxes", function() { dispFormTextFieldTest('Checkboxes', 'SPFieldMultiChoice', 'Alpha; Bravo; Charlie'); }); 32 | test("Checkboxes with Fill-in", function() { dispFormTextFieldTest('Checkboxes with Fill-in', 'SPFieldMultiChoice', 'Alpha; Bravo; Charlie'); }); 33 | test("Number", function() { dispFormTextFieldTest('Number', 'SPFieldNumber', '42'); }); 34 | test("Currency", function() { dispFormTextFieldTest('Currency', 'SPFieldCurrency', '$99.95'); }); 35 | test("Date Only", function() { dispFormTextFieldTest('Date Only', 'SPFieldDateTime', '3/5/2016'); }); 36 | test("Date and Time", function() { dispFormTextFieldTest('Date and Time', 'SPFieldDateTime', '3/5/2016 4:45 PM'); }); 37 | test("Yes/No", function() { dispFormTextFieldTest('Yes/No', 'SPFieldBoolean', 'No'); }); 38 | 39 | // TODO: implement tests for SPDispFormField 40 | //test("Plain Text", function() { dispFormTextFieldTest('Multi-line Plain Text', 'SPFieldNote', 'Alpha hello world'); }); 41 | }(jQuery)); 42 | -------------------------------------------------------------------------------- /test/test_list_eu.js: -------------------------------------------------------------------------------- 1 | /* Tests specific to SharePoint lists */ 2 | (function() { 3 | module("SPNumberField (Europe)", { 4 | setup: function() { 5 | SPUtility.SetDecimalSeparator(','); 6 | SPUtility.SetThousandsSeparator('.'); 7 | this.field = SPUtility.GetSPField('Number'); 8 | } 9 | }); 10 | 11 | test('GetSPField()', function() { 12 | expect(2); 13 | notStrictEqual(this.field, null, "GetSPField should have returned an object."); 14 | strictEqual(this.field.Type, "SPFieldNumber", "The field's type should be " + this.field.Type); 15 | }); 16 | 17 | test("SetValue() and GetValue()", function() { 18 | expect(2); 19 | 20 | var expected = 50000; 21 | strictEqual(this.field.GetValue(), 22 | expected, 23 | "GetValue should return fifty thousand."); 24 | 25 | expected = 1000000; 26 | this.field.SetValue('1.000.000'); 27 | 28 | strictEqual(this.field.GetValue(), 29 | expected, 30 | "SetValue should set the field to one million."); 31 | }); 32 | 33 | module("SPCurrencyField (Europe)", { 34 | setup: function() { 35 | SPUtility.SetDecimalSeparator(','); 36 | SPUtility.SetThousandsSeparator('.'); 37 | this.field = SPUtility.GetSPField('Currency'); 38 | } 39 | }); 40 | 41 | test('GetSPField()', function() { 42 | expect(2); 43 | notStrictEqual(this.field, null, "GetSPField should have returned an object."); 44 | strictEqual(this.field.Type, "SPFieldCurrency", "The field's type should be " + this.field.Type); 45 | }); 46 | 47 | test("SetValue() and GetValue()", function() { 48 | expect(2); 49 | 50 | var expected = 1234567.89; 51 | strictEqual(this.field.GetValue(), 52 | expected, 53 | "GetValue should return one million two hundred thirty four thousand five hundred sixty seven and eighty nine cents."); 54 | 55 | expected = 1000.95; 56 | this.field.SetValue('1.000,95'); 57 | 58 | strictEqual(this.field.GetValue(), 59 | expected, 60 | "SetValue should set the field to one thousand and ninety five cents."); 61 | }); 62 | }(jQuery)); 63 | -------------------------------------------------------------------------------- /test/test_sputility.js: -------------------------------------------------------------------------------- 1 | /* Main SPUtility.js tests */ 2 | (function($) { 3 | /* 4 | ======== A Handy Little QUnit Reference ======== 5 | http://api.qunitjs.com/ 6 | 7 | Test methods: 8 | module(name, {[setup][ ,teardown]}) 9 | test(name, callback) 10 | expect(numberOfAssertions) 11 | stop(increment) 12 | start(decrement) 13 | Test assertions: 14 | ok(value, [message]) 15 | equal(actual, expected, [message]) 16 | notEqual(actual, expected, [message]) 17 | deepEqual(actual, expected, [message]) 18 | notDeepEqual(actual, expected, [message]) 19 | strictEqual(actual, expected, [message]) 20 | notStrictEqual(actual, expected, [message]) 21 | throws(block, [expected], [message]) 22 | */ 23 | 24 | module("SPUtility.js"); 25 | 26 | test("SPUtility global variable", function() { 27 | expect(1); 28 | strictEqual(typeof SPUtility, 'object', "The SPUtility object should be available."); 29 | }); 30 | 31 | test("SPUtility.GetSPField", function() { 32 | expect(1); 33 | strictEqual(typeof SPUtility.GetSPField, 'function', "SPUtility should have a GetSPField function."); 34 | }); 35 | 36 | test("SPUtility.Setup", function() { 37 | expect(1); 38 | strictEqual(typeof SPUtility.Setup, 'function', "SPUtility should have a Setup function."); 39 | }); 40 | 41 | test("GetSPField throws an error when the field was not found", function() { 42 | throws(function() { 43 | SPUtility.GetSPField('foo bar'); 44 | }, 45 | "Unable to get a SPField named foo bar", 46 | "Correct error was thrown" 47 | ); 48 | }); 49 | 50 | module("SPTextField", { 51 | setup: function() { 52 | this.field = SPUtility.GetSPField('Title'); 53 | } 54 | }); 55 | 56 | test("Get the field", function() { 57 | expect(2); 58 | notStrictEqual(this.field, null, "GetSPField should have returned an object."); 59 | strictEqual(this.field.Type, "SPFieldText", "The field's type should be SPFieldText."); 60 | }); 61 | 62 | test("Get and set the value", function() { 63 | expect(1); 64 | 65 | var expected = 'foo bar'; 66 | this.field.SetValue(expected); 67 | 68 | strictEqual(this.field.GetValue(), 69 | expected, 70 | "SetValue() failed to set Textbox."); 71 | }); 72 | 73 | test("MakeReadOnly()", function() { 74 | expect(1); 75 | 76 | var expected = 'foo bar'; 77 | this.field.SetValue(expected); 78 | this.field.MakeReadOnly(); 79 | 80 | ok('make read only ok'); 81 | }); 82 | 83 | module("SPNumberField", { 84 | setup: function() { 85 | this.field = SPUtility.GetSPField('Number'); 86 | } 87 | }); 88 | 89 | test('GetSPField()', function() { 90 | expect(2); 91 | notStrictEqual(this.field, null, "GetSPField should have returned an object."); 92 | strictEqual(this.field.Type, "SPFieldNumber", "The field's type should be " + this.field.Type); 93 | }); 94 | 95 | test("SetValue() and GetValue()", function() { 96 | expect(1); 97 | 98 | var expected = 42; 99 | this.field.SetValue(expected); 100 | 101 | strictEqual(this.field.GetValue(), 102 | expected, 103 | "SetValue() failed to set Textbox."); 104 | }); 105 | 106 | module("SPCurrencyField", { 107 | setup: function() { 108 | this.field = SPUtility.GetSPField('Currency'); 109 | } 110 | }); 111 | 112 | test('GetSPField()', function() { 113 | expect(2); 114 | notStrictEqual(this.field, null, "GetSPField should have returned an object."); 115 | strictEqual(this.field.Type, "SPFieldCurrency", "The field's type should be " + this.field.Type); 116 | }); 117 | 118 | test("SetValue() and GetValue()", function() { 119 | expect(1); 120 | 121 | var expected = 42; 122 | this.field.SetValue(expected); 123 | 124 | strictEqual(this.field.GetValue(), 125 | expected, 126 | "SetValue() failed to set Textbox."); 127 | }); 128 | 129 | module("SPFieldChoice - Dropdown", { 130 | setup: function() { 131 | this.field = SPUtility.GetSPField('Dropdown Choice'); 132 | } 133 | }); 134 | 135 | test('GetSPField()', function() { 136 | expect(2); 137 | notStrictEqual(this.field, null, "GetSPField should have returned an object."); 138 | strictEqual(this.field.Type, "SPFieldChoice", "The field's type should be " + this.field.Type); 139 | }); 140 | 141 | test("SetValue() and GetValue()", function() { 142 | expect(1); 143 | 144 | var expected = "Charlie"; 145 | this.field.SetValue(expected); 146 | 147 | strictEqual(this.field.GetValue(), 148 | expected, 149 | "SetValue() failed to set Textbox."); 150 | }); 151 | 152 | test("Try setting the field to garbage (throws an exception)", function() { 153 | expect(1); 154 | 155 | throws(function(){ 156 | this.field.SetValue("foo bar"); 157 | }); 158 | }); 159 | 160 | module("SPFieldChoice Dropdown (with fill in)", { 161 | setup: function() { 162 | this.field = SPUtility.GetSPField('Dropdown Choice with Fill-in'); 163 | } 164 | }); 165 | 166 | test('GetSPField()', function() { 167 | expect(4); 168 | notStrictEqual(this.field, null, "GetSPField should have returned an object."); 169 | notStrictEqual(this.field.FillInElement, null, "Fill in element should have an element."); 170 | strictEqual(this.field.FillInAllowed, true, "Fill in should be allowed."); 171 | strictEqual(this.field.Type, "SPFieldChoice", "The field's type should be " + this.field.Type); 172 | }); 173 | 174 | test("SetValue() and GetValue()", function() { 175 | expect(2); 176 | 177 | var expected = "Charlie"; 178 | this.field.SetValue(expected); 179 | 180 | strictEqual(this.field.GetValue(), 181 | expected, 182 | "SetValue() failed to set dropdown."); 183 | 184 | expected = "foo bar"; 185 | this.field.SetValue(expected); 186 | strictEqual(this.field.GetValue(), 187 | expected, 188 | "SetValue() failed to set fill in value."); 189 | }); 190 | 191 | module("SPFieldChoice - Radio buttons", { 192 | setup: function() { 193 | this.field = SPUtility.GetSPField('Radio Buttons'); 194 | } 195 | }); 196 | 197 | test('GetSPField()', function() { 198 | expect(3); 199 | notStrictEqual(this.field, null, "GetSPField should have returned an object."); 200 | strictEqual(this.field.Type, "SPFieldChoice", "The field's type should be " + this.field.Type); 201 | strictEqual( 202 | this.field.RadioButtons.length, 203 | 5, 204 | "RadioButtons property is not set or is set to the wrong to the wrong DOM object."); 205 | }); 206 | 207 | test("SetValue() and GetValue()", function() { 208 | expect(1); 209 | 210 | var expected = "Charlie"; 211 | this.field.SetValue(expected); 212 | 213 | strictEqual(this.field.GetValue(), 214 | expected, 215 | "SetValue() failed to set Radio button."); 216 | }); 217 | 218 | test("Try setting the field to garbage (throws an exception)", function() { 219 | expect(1); 220 | 221 | throws(function(){ 222 | this.field.SetValue("foo bar"); 223 | }); 224 | }); 225 | 226 | module("SPFieldChoice - Radio buttons with fill-in", { 227 | setup: function() { 228 | this.field = SPUtility.GetSPField('Radio Buttons with Fill-in'); 229 | } 230 | }); 231 | 232 | test('GetSPField()', function() { 233 | expect(3); 234 | notStrictEqual(this.field, null, "GetSPField should have returned an object."); 235 | strictEqual(this.field.Type, "SPFieldChoice", "The field's type should be " + this.field.Type); 236 | strictEqual( 237 | this.field.RadioButtons.length, 238 | 3, 239 | "RadioButtons property is not set or is set to the wrong to the wrong DOM object."); 240 | }); 241 | 242 | test("SetValue() and GetValue()", function() { 243 | expect(1); 244 | 245 | var expected = "Charlie"; 246 | this.field.SetValue(expected); 247 | 248 | strictEqual(this.field.GetValue(), 249 | expected, 250 | "SetValue() failed to set Radio button."); 251 | }); 252 | 253 | test("Set the fill-in value", function() { 254 | expect(2); 255 | 256 | var expected = "foo bar"; 257 | this.field.SetValue(expected); 258 | strictEqual(this.field.GetValue(), 259 | expected, 260 | "SetValue should set the fill-in textbox."); 261 | strictEqual($(this.field.FillInTextbox).val(), 262 | expected, 263 | "Expect the fill-in textbox to be set correctly."); 264 | }); 265 | 266 | module("SPFieldChoice - Checkboxes", { 267 | setup: function() { 268 | this.field = SPUtility.GetSPField('Checkboxes'); 269 | } 270 | }); 271 | 272 | test('GetSPField()', function() { 273 | expect(3); 274 | notStrictEqual(this.field, null, "GetSPField should have returned an object."); 275 | strictEqual(this.field.Type, "SPFieldMultiChoice", "The field's type should be " + this.field.Type); 276 | strictEqual( 277 | this.field.Checkboxes.length, 278 | 5, 279 | "There are not 5 checkboxes."); 280 | }); 281 | 282 | test("SetValue() and GetValue()", function() { 283 | expect(1); 284 | 285 | var expected = ["Alpha", "Charlie"]; 286 | this.field.SetValue("Alpha", true); 287 | this.field.SetValue("Charlie", true); 288 | 289 | deepEqual(this.field.GetValue(), 290 | expected, 291 | "SetValue() failed to set the checkbox."); 292 | }); 293 | 294 | test("Try setting the field to garbage (throws an exception)", function() { 295 | expect(1); 296 | 297 | throws(function(){ 298 | this.field.SetValue("foo bar"); 299 | }); 300 | }); 301 | 302 | module("SPFieldChoice - Checkboxes with Fill-in", { 303 | setup: function() { 304 | this.field = SPUtility.GetSPField('Checkboxes with Fill-in'); 305 | } 306 | }); 307 | 308 | test('GetSPField()', function() { 309 | expect(5); 310 | notStrictEqual(this.field, null, "GetSPField should have returned an object."); 311 | notStrictEqual(this.field.FillInElement, null, "Fill in element should have an element."); 312 | strictEqual(this.field.FillInAllowed, true, "Fill in should be allowed."); 313 | strictEqual(this.field.Type, "SPFieldMultiChoice", "The field's type should be SPFieldMultiChoice"); 314 | strictEqual( 315 | this.field.Checkboxes.length, 316 | 5, 317 | "There are not 5 checkboxes."); 318 | }); 319 | 320 | test("SetValue() and GetValue()", function() { 321 | expect(2); 322 | 323 | var expected = ["Alpha", "Charlie"]; 324 | this.field.SetValue("Alpha", true); 325 | this.field.SetValue("Charlie", true); 326 | 327 | deepEqual(this.field.GetValue(), 328 | expected, 329 | "SetValue() failed to set the checkbox."); 330 | 331 | // pass a value to fill-in 332 | this.field.SetValue("foo bar"); 333 | expected.push("foo bar"); 334 | deepEqual(this.field.GetValue(), 335 | expected, 336 | "Fill-in value should be set now."); 337 | }); 338 | 339 | 340 | 341 | module("SPFieldDateTime (date only)", { 342 | setup: function() { 343 | this.field = SPUtility.GetSPField('Date Only'); 344 | } 345 | }); 346 | 347 | test('GetSPField()', function() { 348 | expect(2); 349 | notStrictEqual(this.field, null, "GetSPField should have returned an object."); 350 | strictEqual(this.field.Type, "SPFieldDateTime", "The field's type should be " + this.field.Type); 351 | }); 352 | 353 | test("SetValue() takes one string parameter", function() { 354 | expect(1); 355 | 356 | var expected = "8/15/2013"; 357 | this.field.SetValue(2013, 8, 15); 358 | 359 | var actual = this.field.GetValue(); 360 | equal(actual.toString(), 361 | expected, 362 | "SetValue() didn't set the date textbox."); 363 | }); 364 | 365 | 366 | module("SPFieldDateTime (date and time)", { 367 | setup: function() { 368 | this.field = SPUtility.GetSPField('Date and Time'); 369 | } 370 | }); 371 | 372 | test('GetSPField()', function() { 373 | expect(2); 374 | notStrictEqual(this.field, null, "GetSPField should have returned an object."); 375 | strictEqual(this.field.Type, "SPFieldDateTime", "The field's type should be " + this.field.Type); 376 | }); 377 | 378 | test("SetValue() takes year, month, day, hour (str), and minute (str) parameters", function() { 379 | expect(1); 380 | 381 | var expected = "8/15/2013 8:30 AM"; 382 | this.field.SetValue(2013, 8, 15, '8 AM', '30'); 383 | 384 | var actual = this.field.GetValue(); 385 | equal(actual.toString(), 386 | expected, 387 | "SetValue() didn't set the date textbox."); 388 | }); 389 | 390 | test("SetValue() takes year, month, day, hour (integer), and minute (str) parameters", function() { 391 | expect(1); 392 | 393 | var expected = "8/15/2013 8:30 AM"; 394 | this.field.SetValue(2013, 8, 15, 8, '30'); 395 | 396 | var actual = this.field.GetValue(); 397 | equal(actual.toString(), 398 | expected, 399 | "SetValue() didn't set the date textbox."); 400 | }); 401 | 402 | test("SetValue() takes null or empty string to clear the field", function() { 403 | expect(1); 404 | 405 | var expected = ""; // should be empty string instead of just the time 406 | this.field.SetValue(null); 407 | 408 | var actual = this.field.GetValue().toString(); 409 | equal(actual, 410 | expected, 411 | "SetValue() didn't set the date textbox."); 412 | }); 413 | 414 | 415 | module("SPBooleanField (yes/no)", { 416 | setup: function() { 417 | this.field = SPUtility.GetSPField('Yes/No'); 418 | } 419 | }); 420 | 421 | test('GetSPField()', function() { 422 | expect(2); 423 | notStrictEqual(this.field, null, "GetSPField should have returned an object."); 424 | strictEqual(this.field.Type, "SPFieldBoolean", "The field's type should be " + this.field.Type); 425 | }); 426 | 427 | test("GetValue() and SetValue()", function() { 428 | expect(1); 429 | 430 | var expected = true; 431 | this.field.SetValue(true); 432 | 433 | var actual = this.field.GetValue(); 434 | equal(actual, 435 | expected, 436 | "SetValue() didn't set the checkbox."); 437 | }); 438 | 439 | module("SPFieldNote (multi-line, plain text)", { 440 | setup: function() { 441 | this.field = SPUtility.GetSPField('Multi-line Plain Text'); 442 | } 443 | }); 444 | 445 | test('GetSPField()', function() { 446 | expect(2); 447 | notStrictEqual(this.field, null, "GetSPField should have returned an object."); 448 | strictEqual(this.field.Type, "SPFieldNote"); 449 | }); 450 | 451 | test("GetValue() and SetValue()", function() { 452 | expect(2); 453 | 454 | var expected = 'Hello world!'; 455 | this.field.SetValue(expected); 456 | 457 | // make sure the select was set correctly 458 | equal($(this.field.Textbox).val(), expected); 459 | 460 | var actual = this.field.GetValue(); 461 | strictEqual(actual, expected); 462 | }); 463 | }(jQuery)); 464 | -------------------------------------------------------------------------------- /test/test_survey_2013.js: -------------------------------------------------------------------------------- 1 | (function($) { 2 | module("SPFieldGridChoice", { 3 | setup: function() { 4 | this.field = SPUtility.GetSPField('Rating Scale'); 5 | } 6 | }); 7 | 8 | test("Get the field", function() { 9 | expect(2); 10 | notStrictEqual(this.field, null, "GetSPField returned null (should have returned an object)."); 11 | strictEqual(this.field.Type, "SPFieldGridChoice", "Wrong type: " + this.field.Type); 12 | }); 13 | 14 | test("The static function to get SPFields is available.", function() { 15 | ok(SPUtility.GetSPField); 16 | ok($); 17 | }); 18 | }(jQuery)); 19 | -------------------------------------------------------------------------------- /test/test_survey_dispform_2013.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | module("Survey DispForm"); 3 | 4 | // TODO: test special survey fields like Rating Scale 5 | }(jQuery)); 6 | --------------------------------------------------------------------------------