Page 1 of 1

How to access "child" values from "Parent" SharePoint fields

Posted: 19 Dec 2014
by Jdubs
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: viewtopic.php?f=4&t=44 but it did not work.

I tried this solution: viewtopic.php?f=4&t=154 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!

Re: How to access "child" values from "Parent" SharePoint fields

Posted: 19 Dec 2014
by Dmitry Kozlov
Hi,

You can find how to get/set different types of fields in the following post:
http://spform.com/forms-designer- ... eld-values

Re: How to access "child" values from "Parent" SharePoint fields

Posted: 19 Dec 2014
by Jdubs
Thank you for the prompt reply. The http://spform.com/forms-designer- ... eld-values was referenced in one of the links I provided.


The problem is this:

Choice Multiple Get
var 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.

Re: How to access "child" values from "Parent" SharePoint fields

Posted: 19 Dec 2014
by Jdubs
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

Re: How to access "child" values from "Parent" SharePoint fields

Posted: 22 Dec 2014
by Dmitry Kozlov
You can retrieve an array of the selected indices following way:

Code: Select all

fd.field('MultiChoice').value()
Next, you can check whether a particular option is selected:

Code: Select all

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!');
}

Re: How to access "child" values from "Parent" SharePoint fields

Posted: 26 Dec 2014
by Jdubs
Thank you Dmitry!