I got this request from Larry:
Add this code to a CEWP below the form in NewForm or EditForm: Alter the reference to jQuery as needed.
You also might want to take a look at this one:
Limit number of allowed selections in Checkboxes choice
choice – Multiple select, check boxes, is there a way to have multiple default values. I may want the same 3 items to always be selected. by default SP only allows one option. This field for 90% may need those 3 requests. Can it be done?
Add this code to a CEWP below the form in NewForm or EditForm: Alter the reference to jQuery as needed.
| 01 | <script type="text/javascript"src="../../Javascript/jquery-1.3.2.min.js"></script> | 
| 02 | <script type="text/javascript"> | 
| 03 | /* Multiple default values in a column of type "Checkboxes (allow multiple selections)" | 
| 04 |  * Created by Alexander Bautz | 
| 05 |  * alexander.bautz@gmail.com | 
| 07 |  * v1.0 | 
| 08 |  * LastMod: 22.02.2010 | 
| 09 |  * | 
| 10 |  Sets the default value of a column of type "Checkboxes (allow multiple selections)", | 
| 11 |  by passing the FieldInternalName of the SharePoint-field with an array of values to prefill. | 
| 12 | */ | 
| 13 | fields = init_fields(); | 
| 14 | // Define the array if values | 
| 15 | varmyArr = ['Choice 4','Choice 9']; | 
| 16 | // Call the function with the FieldInternalName of the field and the array. | 
| 17 | setMultiSelectDefaultValues('MyMultiChoice',myArr); | 
| 18 | 
| 19 | functionsetMultiSelectDefaultValues(FieldInternalName,arrOfValues){ | 
| 20 |     $(fields[FieldInternalName]).find('input:checkbox').each(function(){ | 
| 21 |         varthisText = $(this).next().text(); | 
| 22 |         if($.inArray(thisText,arrOfValues)>-1){ | 
| 23 |             $(this).attr('checked',true); | 
| 24 |         } | 
| 25 |     }); | 
| 26 | } | 
| 27 | 
| 28 | functioninit_fields(){ | 
| 29 |   varres = {}; | 
| 30 |   $("td.ms-formbody").each(function(){ | 
| 31 |       if($(this).html().indexOf('FieldInternalName="')<0) return; | 
| 32 |       varstart = $(this).html().indexOf('FieldInternalName="')+19; | 
| 33 |       varstopp = $(this).html().indexOf('FieldType="')-7; | 
| 34 |       varnm = $(this).html().substring(start,stopp); | 
| 35 |       res[nm] = this.parentNode; | 
| 36 |   }); | 
| 37 |   returnres; | 
| 38 | } | 
| 39 | </script> | 
Limit number of allowed selections in Checkboxes choice
 
No comments:
Post a Comment