Radio button if statements

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
User avatar
Roo
Posts: 107
Joined: Tue Oct 24, 2017

16 Feb 2018

I've read quite a few comments on the forums here about radio button control (and have also visited the control site https://spform.com/javascript-framework ... eld-values)

However I'm struggling work out how to check the value of the radio button label.

I have a radio control (internal name 'IssueType') with 7 choices
Audit
Environment
internal etc etc

If I want to control other elements of the form from what has been choosen I used this:

function showHideFields(){
if (fd.field('IssueType').value() == 'Audit') {
$('.TAbleAudit').show();
}
else {
$('.TAbleAudit').hide();
}
}

//call the function on opening
showHideFields();

However, it doesn't work - Do I have to store the value as a variable and then use the variable within the if statement?

User avatar
Roo
Posts: 107
Joined: Tue Oct 24, 2017

16 Feb 2018

I've got around this by using the index number (I had previous tried this, but without the "") so the code is as follows if it helps anyone:

function showHideFields(){
if (fd.field('IssueType').value() == "1") {
$('.TAbleAudit').show();
}
else{
$('.TAbleAudit').hide();
}
}


//call the function on opening
showHideFields();

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

16 Feb 2018

Dear Roo,
Good job! I didn't even have time to answer the question, but yes, you are correct, by default Radio button choice returns number of the choice, instead of text. To get the text, you can use the following code, even though it's a bit lengthy:

Code: Select all

var issueTypeNum = fd.field('IssueType').value();
if (fd.field('IssueType').control()._el().find('td').eq(issueTypeNum).find('label').text()  == 'Audit'){
}
Cheers

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 11 guests