Page 1 of 1

Available Choices in Edit/New Form

Posted: 26 Jan 2016
by armin o
I want to set a dynamic default value of a single-value choice field (radio button type).

Q: How do i get the available choices as e.g. array of strings in order to determin the index of the choice value i want to set?


Thanks,
Armin

Re: Available Choices in Edit/New Form

Posted: 27 Jan 2016
by armin o
I do this to get the array of (unselected) choices inside the new field: fd.field('SF_x0020_Lot_x0020_No').control()._el()[0]
.innerText.split('\n'); Two drawbacks: - Only works as long as nothing is actually selected. - Must be considered a hack
-Armin

Re: Available Choices in Edit/New Form

Posted: 27 Jan 2016
by rostislav
Hello,

Code: Select all

fd.field('choice').control()._el().find('td');
will get you all radio buttons in their correct order.

Code: Select all

fd.field('choice').control()._el().find('td').length
will give you how many buttons there are

Code: Select all

fd.field('choice').control()._el().find('td').eq(1)
will give you the second button

Code: Select all

fd.field('choice').control()._el().find('td').eq(1).find('label').text()
will give you the label of the second button

Code: Select all

fd.field('choice').control()._el().find('td').find('label')
will give you the labels of all buttons in their correct order


Code: Select all

fd.field('choice').control()._el().find('td').find('label').each(function( index ) {
console.log( index + ": " + $( this ).text() );
});
will print you all the labels with their indicies.

Re: Available Choices in Edit/New Form

Posted: 28 Jan 2016
by armin o
Good morning Rostislav,

thank you for your detailed answer!

from http://spform.com/forms-designer- ... eld-values :

fd.field('ChoiceSingle').value('B');
does not work for me. Instead of 'B' i set the value like this:
fd.field('ChoiceSingle').value(ChoiceSingleChoices.indexOf('B'));
Maybe this is a documentation bug...
Best wishes,
Armin

Re: Available Choices in Edit/New Form

Posted: 28 Jan 2016
by armin o
Sorry, i just flaged my last post while searching for a way to edit...Please ignore ;)