SPUtility.js 0.8 and beyond!
By Kit
Quick update to SPUtility.js today! I’ve added support for rich text fields, unchecking multi-select checkboxes, and choice fields with fill-in values. I also have some thoughts on future SPUtility.js updates.
Support for rich text fields
This is an update to the SPNoteField class. In order to get this working, I had to do some funky stuff with internal SharePoint JavaScript functions: <span class=“text”>RTE_GetEditorIFrame</span>
, <span class=“text”>RTE_GetIFrameContents</span>
, and <span class=“text”>RTE_TransferTextAreaContentsToIFrame</span>
.
Support for unchecking multi-select checkboxes
I think this really was a bug, but I found that there was no way to uncheck one of the choices of a multi-select choice field. I updated the SetValue function to take an optional boolean second parameter. Passing it true will check the choice… false will uncheck.
SPUtility.GetSPField('Multiselect Column').SetValue('Bravo', false);
Support for choice fields with fill-in values
I finally buckled down and implemented the code to support choice fields with fill-in values. Turns out this was a little more complicated than I first expected. I’m not sure how this will work with languages other than english because it seems difficult to find the “Specify your own value” radio button. It also complicates the SPChoiceField class quite a bit.
Either way, I tried to keep things as simple as possible and keep most of the burden in the library rather than on the developer/user:
- Detects the presence of the fill-in textbox for every different type of choice field (radio, dropdown, multi-select)
<span class=“text”>SetValue</span>
is smart: if the value passed is a choice, then that choice is set. If not, then the fill-in value is set.<span class=“text”>GetValue</span>
is also able to detect when the fill-in value is present
I’m hoping to break some of this logic down into smaller classes in the future but this will really all be cleanup work on my end. Which leads me into the next part…
Thoughts about future updates
My wishlist for future updates currently is:
- Better documentation!
I plan to start using [PDoc](http://pdoc.org/) (what Prototype.js uses for it's [API documentation](http://api.prototypejs.org/))
- To support #1, I’d like to break SPUtility.js into more manageable chunks and use Sprockets
- To support #1 and #2, I’d like to start using github for the day to day version control. This is something I debated but I think I can use it for the full source and still use the codeplex site for the releases. I’m not sure where I’ll host the documentation yet.
Go download SPUtility.js at http://sputility.codeplex.com/. Feel free to post comments with feedback!