Tuesday, November 12, 2013

Use SharePoint Modal Dialog to Prompt for Text

You need to prompt the user for some text from somewhere within a SharePoint site. How to you go about this?
  1. Use the JavaScript 'window.prompt' method? Too ugly and limited style and validation options.
  2. Incorporate a jQuery plugin that makes for easy prompting? May or may not work with SharePoint, and even then it will most likely have a UI style that is different.
  3. Use the SharePoint dialog API to show a modal page? Close - but that means we have to create and deploy an entire ASPX or HTM page to show within the dialog. That is a lot for what boils down to a label and a text box.
  4. Embed the script below and move on to checking on your Klout status.

Yeah, I like #4 too - except for the Klout part.


What this script does:
  • Shows a SharePoint modal dialog and injects content and style, so it looks like the rest of your UI.
  • Does not require you to build another page for the dialog UI.
  • Returns the text the user entered.
  • Validates that the user typed in something by default. You can optionally provide a maximum length or a custom validation function to use.
  • Requires jQuery. Probably could be written to be dependency-free, but that would be many more lines of code - especially the CSS cloning part.

 
© I caught you a delicious bass.
Back to top