Skip to content

Instantly share code, notes, and snippets.

@iamrobert
Last active September 28, 2021 18:23
Show Gist options
  • Select an option

  • Save iamrobert/013415dfdfad47fd53e39d7efe3e09ff to your computer and use it in GitHub Desktop.

Select an option

Save iamrobert/013415dfdfad47fd53e39d7efe3e09ff to your computer and use it in GitHub Desktop.
Flexi-tut.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<p> I wanted a way when admins click "other", then the hidden field would show<br>
(<strong>'Other Job Title'</strong>):<br>
<img src="https://i.imgur.com/s7uHwAF.png?1632841925283" alt="Explanation" data-mce-src="https://i.imgur.com/s7uHwAF.png"><br>
<br>
</p>
<p>We have 2 fields:<br>
<br>
</p>
<ul>
<li>Job Title - Radio Field | ID = 70 |&nbsp; Field alias: <code>job_title</code></li>
<li>Other Job Title - Text Field | ID = 101 |&nbsp; Field alias: <code>other_job_title</code></li>
</ul>
<p><img src="https://i.imgur.com/WLMu9Ak.png?1632841925283" alt="Radio Field" data-mce-src="https://i.imgur.com/WLMu9Ak.png"></p>
<p>In your FLEXIcontent Type Item Form (add the following):</p>
<pre class="">//HIDE OTHER JOB FIELD
&nbsp;&nbsp;&nbsp;
$('#label_outer_fcfield_101, #container_fcfield_101').hide();
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;//RADIO FIELDS NAME
&nbsp;&nbsp;&nbsp;$('input[name="custom[job_title][0]"]').change(&nbsp;&nbsp;&nbsp;&nbsp;function() {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;//RADIO OTHER VALUE&nbsp;
&nbsp;&nbsp; &nbsp;if (this.checked &amp;&amp; this.value == 'other') {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;$('#label_outer_fcfield_101, #container_fcfield_101').show();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;}
&nbsp;&nbsp; &nbsp;else {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;$('#label_outer_fcfield_101, #container_fcfield_101').hide();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;$('#container_fcfield_101 input').val('');&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;
});
&nbsp;
//ON OPEN/LOAD
if ($('input#custom_job_title_0_2').is(':checked') == true) { &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;$('#label_outer_fcfield_101, #container_fcfield_101').show();&nbsp;
}</pre>
<p>Here's an image shot of this:<br>
<img src="https://i.imgur.com/IVbIasZ.png?1632841942535" alt="Explanation" data-mce-src="https://i.imgur.com/IVbIasZ.png"><br>
</p>
<p>Finally - I used the following code in my item template to get it to work:</p>
<p>Here's an image shot of this:<br>
<img src="https://i.imgur.com/IVbIasZ.png?1632841959258" alt="Explanation" data-mce-src="https://i.imgur.com/IVbIasZ.png"><br>
<br>
Finally - I used the following code in my item.php template to get it to work:<br>
<br>
</p>
<pre>
$job_title = '';
FlexicontentFields::getFieldDisplay( $item, "job_title", null, 'display', 'item' );
FlexicontentFields::getFieldDisplay( $item, "other_job_title", null, 'display', 'item' );
$job_title = $item->fields[ "other_job_title" ]->display;
if ( $job_title == '' ) {
$job_title = $item->fields[ "job_title" ]->display;
}
echo $job_title;
</pre>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment