How to access "child" values from "Parent" SharePoint fields
Posted by Jdubs - Dec 19 ’14 at 11:12
I can't seem to figure out how to dynamically access the child values for SharePoint fields that have multiple values.
For example:
- Checkbox field: If I have 2 (or more) checkbox values for ONE "Parent" Checkbox SharePoint field, how do I access the values of the various "child" checkbox values so that I can make the form perform certain actions depending on which checkbox (or more) are checked?
- Date AND Time field: The SharePoint Date and Time field populates with THREE values: Date, Hour, and Minute. How do I access the "Hour" field and the "Minute" field so that I can pre-populate those boxes with the current hour and minute?
- Radio button: If I have a Radio button SharePoint field, how do I access the multiple choices a user can make on the single Radio box?
I tried this solution: http://forum.spform.com/forms-designer/multiple-choice-30/ but it did not work.
I tried this solution: http://forum.spform.com/forms-designer/multi-selection-choice-20115/ but it only works by checking the value of ONE "child" value. I need to dynamically be able to access any (or all) of the child values.
In HTML this is easy: document.getElementById("childValue") allows you to access and sub element directly.
Thanks!
-
Dmitry KozlovAdminMember for: 10 years 11 days
Hi,
You can find how to get/set different types of fields in the following post:
http://formsdesigner.blogspot.com/2013/04/getting-and-setting-sharepoint-form.html
-
JdubsMemberMember for: 8 years 9 months 14 days
Thank you for the prompt reply. The http://formsdesigner.blogspot.com/2013/04/getting-and-setting-sharepoint-form.html was referenced in one of the links I provided.
The problem is this:
Choice Multiple Getvar checkboxIndex = 2; //You are setting an absolute index value here; this code will not work if the user selects a value other than 2.
fd.field('MultiChoice').control()._el() .find('input[type="checkbox"]').eq(checkboxIndex)//Again, this only checks if checkbox value is = 2. What about 0, 1, 3, etc.? .is(':checked');
The other problem:
OnChange
fd.field('MultiChoice').change(function(){ alert('Field changed!');//This checks if the FIELD changes, but I still can not retrieve the value.
});//When the field changes, I want to be able to change the form dynamically, depending on if they chose Choice 1, Choice 2, Choice 1 AND 2, etc.
-
JdubsMemberMember for: 8 years 9 months 14 days
[#2]: Sorry, looks like my previous reply did not render properly.
Here's what my comments said:
Problem:
//You are setting an absolute index value here; this code will not work if the user selects a value other than 2.
//Again, this only checks if checkbox value is = 2. What about 0, 1, 3, etc.?
The other problem:
//This checks if the FIELD changes, but I still can not retrieve the value.
//When the field changes, I want to be able to change the form dynamically, depending on -
Dmitry KozlovAdminMember for: 10 years 11 days
[#3]: You can retrieve an array of the selected indices following way:
fd.field('MultiChoice').value()
Next, you can check whether a particular option is selected:
if ($.inArray(0, fd.field('MultiChoice').value())) { alert('The first option is selected!'); } if ($.inArray(1, fd.field('MultiChoice').value())) { alert('The second option is selected!'); }
-
JdubsMemberMember for: 8 years 9 months 14 days
Thank you Dmitry!