Last active
September 28, 2021 18:23
-
-
Save iamrobert/013415dfdfad47fd53e39d7efe3e09ff to your computer and use it in GitHub Desktop.
Flexi-tut.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!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 | Field alias: <code>job_title</code></li> | |
| <li>Other Job Title - Text Field | ID = 101 | 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 | |
| | |
| $('#label_outer_fcfield_101, #container_fcfield_101').hide(); | |
| | |
| //RADIO FIELDS NAME | |
| $('input[name="custom[job_title][0]"]').change( function() { | |
| | |
| //RADIO OTHER VALUE | |
| if (this.checked && this.value == 'other') { | |
| $('#label_outer_fcfield_101, #container_fcfield_101').show(); | |
| } | |
| else { | |
| $('#label_outer_fcfield_101, #container_fcfield_101').hide(); | |
| $('#container_fcfield_101 input').val(''); | |
| } | |
| }); | |
| | |
| //ON OPEN/LOAD | |
| if ($('input#custom_job_title_0_2').is(':checked') == true) { | |
| $('#label_outer_fcfield_101, #container_fcfield_101').show(); | |
| }</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