This project is read-only.

SP2010 Form Manipulator

by Gunjan Datta


I wanted a way to easily manipulate the field items, without deploying solutions to the server. You basically use the 'display name' of the field as shown on the screen with these methods, to return the object. I know better options are out there, but I wanted to work specifically w/ SPF. My hope is that this will help other developers out there. I plan to add to it, based on feedback.

List of methods in GD_Common

Here are a list of methods in my common library

All Fields/Generic Methods:
  1. disableObject - GD_Common.disableObject(field name)
  2. disableSave - GD_Common.disableSave()
  3. enableObject - GD_Common.enableObject(field name)
  4. enableSave - GD_Common.enableSave()
  5. getFieldValue - GD_Common.getFieldValue(field name)
  6. getObject - GD_Common.getObject(field name)
  7. isDisabled - GD_Common.isDisabled(field name)
  8. isNumber - GD_Common.isNumber(value)
  9. trim - GD_Common.trim(value)

Drop Down List Fields:
  1. getSelectedText - GD_Common.getSelectedText(field name)
  2. getSelectedValue - GD_Common.getSelectedValue(field name)

Drop Down List Fields (<25 values rendered as select)
  1. addItemAtBeginning - GD_Common.dropdownlists.addItemAtBeginning(field name, text, value)
  2. addItemAtEnd - GD_Common.dropdownlists.addItemAtEnd(field name, text, value)
  3. bindItems - GD_Common.dropdownlists.bindItems(field name, items, text field, value field)
  4. clearItems - GD_Common.dropdownlists.clearItems(field name)
  5. deleteItemByText - GD_Common.dropdownlists.deleteItemByText(field name, text)
  6. deleteItemByValue - GD_Common.dropdownlists.deleteItemByValue(field name, value)
  7. deleteSelectedItem - GD_Common.dropdownlists.deleteSelectedItem(field name)
  8. getItem - GD_Common.dropdownlists.getItem(field name)
  9. getItemByText - GD_Common.dropdownlists.getItemByText(field name, text)
  10. getItemByValue - GD_Common.dropdownlists.getItemByValue(field name, value)
  11. getSelectedItem - GD_Common.dropdownlists.getSelectedItem(field name)
  12. setSelectedIndex - GD_Common.dropdownlists.setSelectedIndex(field name, index)
  13. setSelectedItemByText - GD_Common.dropdownlists.setSelectedItemByText(field name, text)
  14. setSelectedItemByValue - GD_Common.dropdownlists.setSelectedItemByValue(field name, value)
  15. sortItems - GD_Common.dropdownlists.sortItems(field name, sort by value flag boolean)

  1. addEvent - GD_Common.addEvent(field name, event type, method)
  2. deleteEvent - GD_Common.deleteEvent(field name, event type, method)
  3. executeEvent - GD_Common.executeEvent(field name, event type)

Field Sections:
  1. getItem - GD_Common.fieldSections.getItem(field name)
  2. getFieldValue - GD_Common.fieldSections.getFieldValue(field name)
  3. hideField - GD_Common.fieldSections.hideField(field name)
  4. hideFields - GD_Common.fieldSections.hideFields(array of field names)
  5. isHidden - GD_Common.fieldSections.isHidden(field name)
  6. showField - GD_Common.fieldSections.showField(field name)
  7. showFields - GD_Common.fieldSections.showFields(array of field names)

  1. executeRestQuery - GD_Common.executeRestQuery(url, callback method)

Text Boxes:
  1. clear - GD_Common.textboxes.clear(field name)
  2. getItem - GD_Common.textboxes.getItem(field name)
  3. getValue - GD_Common.textboxes.getValue(field name)
  4. setValue - GD_Common.textboxes.setValue(field name)

List of variables in GD_ParentChild

  1. selectedValues - Array of current values to prevent the lookup from executing on the same value. Also useful if you have multiple fields acting as a parent to a child.

List of methods in GD_ParentChild

Here are a list of methods in my common library
  1. addParent - GD_ParentChild.addParent(field name, key)
  2. addChild - GD_ParentChild.addChild(parent field name, field name, REST url, text field)
  3. clearDdl - GD_ParentChild.clearDdl(field name)
  4. initParent - GD_ParentChild.initParent(field name)

Parent/Child Example

Here is an example of the main reason why I created this, the "Parent/Child" relationship of lookup fields. My goal is to create a simple solution for developers.

Lists used in this example
  1. Clients - Lists of clients containing ClientId, ClientName, etc
  2. Contacts - List of all contacts w/ a lookup field referencing the client list
  3. Locations - List of all locations w/ a lookup field referencing the client list
  4. Tasks - List containing a lookup field to all of the lists above

This solution uses the built in list data service new to SPF. The first thing you should do is ensure it's working. I will access the client list, and note the client id lookup field name:


After I note the lookup field names for the lists, I will add a content web editor to the Tasks list (new/edit) form. The content editor will need to include the .js scripts. Your path will change, depending on where you store it:

// Reference to scripts
<script type='text/javascript' src='/_layouts/GDQuery/GD_Common.js'></script>
<script type='text/javascript' src='/_layouts/GDQuery/GD_ParentChild.js'></script>

Now here is the code to create a parent/child relationship between the contact & location lookup fields to the client lookup field.

// Script in content editor
<script type='text/javascript'>
  ExecuteOrDelayUntilScriptLoaded('InitParentChild', 'SP.js');

  function InitParentChild() {
    // Create the parent
    GD_ParentChild.addParent('Client', 'ClientId');

    // Create the child
    GD_ParentChild.addChild('Client', 'Contact', '/gdquery/_vti_bin/listdata.svc/Contacts', 'FullName');
    GD_ParentChild.addChild('Client', 'Location', '/gdquery/_vti_bin/listdata.svc/Locations', 'Location');

    // Execute the init method

This code will do the following and has been tested to work with:
  1. Disable the Parent/Child drop down lists until the data has been loaded
  2. Tested with lookup fields both rendered as a drop down (select) & input text box (> 25 list items)
  3. Tested to work w/ hideField & showField methods (Fixed Bug - hiding a lookup field and trying to access another due to generated select element for > 25 list items)
  4. Tested to work w/ multiple parents controlling a child field
    1. Note - This will require additional javascript to handle this unique situation

Last edited Oct 28, 2011 at 3:09 AM by djgonzo81, version 9


No comments yet.