I'm building a custom form and need to place on it a select (drop down) field. I want to populate the select field with job advertisements (they're just standard pages). So I'm thinking the way to do this might be an asset listing to grab me the asset name (job title), and somehow build the select field around it. Would this be the way to go? and has anyone got an sample code of it working?
On the form I've also got a radio list, selecting one or the other would show or hide the next question. Does anyone have the code logic for doing this? as the custom form details page doesn't give me the option to do this.
1 point for answering one of these, and 3 points for giving both. Earn 5 points in the same week and you may go into a draw to win a free beer, wine or soft drink.
Asset listing as from select field
[quote]
I'm building a custom form and need to place on it a select (drop down) field. I want to populate the select field with job advertisements (they're just standard pages). So I'm thinking the way to do this might be an asset listing to grab me the asset name (job title), and somehow build the select field around it. Would this be the way to go? and has anyone got an sample code of it working?
[/quote]
Yeah, you can do this, but you need to populate a text field rather than a select, as the select won't take input that isn't already there as fields of that custom form question. So, create a new text field, and add its keyword to your body copy. Then, preview the page, and note down what the input name and ID are. Then, just build your select list using an asset listing, and for the select name, use the one that was from your text field. Then, just make sure to remove the text field keyword.
[quote]
On the form I've also got a radio list, selecting one or the other would show or hide the next question. Does anyone have the code logic for doing this? as the custom form details page doesn't give me the option to do this.
[/quote]
This would highly depend on the markup that you have around the input fields. But, here is what I have used (https://www.puc.edu/alumni/give-online):
What prompted you to give today?
-- Choose one --Letter from PUCPhonathon CallPersonal ConversationEmail RequestOther
Other:
Then, using some jQuery, do:
// Show "other" field $('#q30305_q8').change(function() { var t = $(this); var p = t.parents('div.formItem'); var n = p.next('div.formItem'); if ((t.val() == 'Other (Please specify)') || (t.val() == 'Other')) { n.show(); } else { n.hide(); n.find('input').val(''); }//end else });//end change
Obviously you would need to adjust both of these code examples for your use case.
Thanks Nic,
All sorted, I've followed your advice and created a text field, then on the bodycopy contents page I just replaced the text field with a nested asset listing. The asset listing checks for all the jobs in the jobs folder and displays the job title like this:
%asset_name% -- Select Position -- %asset_listing%
Then for the show/hide options I just put and a simple javascript onlick action to hide the div, as per below. The only issue I may face now is I think the client want to make some of the hidden fields mandatory if shown. Any ideas?
Code for radio buttons:
<!-- javascript --> function showMessage(which) { if (which == 1) { document.getElementById("permit").style.display = "block"; } else { document.getElementById("permit").style.display = "none"; document.getElementById("permitShow").style.display = "none"; } } <!-- radio button --> <div class="form-block radio-div"><!-- citizenship --> Are you an Australian citizen or resident? <ul><li><input type="radio" name="q37095:q12" id="q37095_q12_0" value="0" class="sq-form-field" onclick = "showMessage(2)"/> <label for="q37095_q12_0">Yes</label></li><li><input type="radio" name="q37095:q12" id="q37095_q12_1" value="1" class="sq-form-field" onclick = "showMessage(1)"/> <label for="q37095_q12_1">No</label></li></ul> </div></pre>
[quote]
The only issue I may face now is I think the client want to make some of the hidden fields mandatory if shown. Any ideas?
[/quote]
No, this isn't possible outside of using javascript for validation.
Just one problem with solution number 1 for grabbing the option fields on the select from via an asset listing.
I attemted to follow these steps and form validation fails every time. Also when the validation fails the select list goes back to original blank state and some text fields further down the page have all their text removed.
Yeah, you can do this, but you need to populate a text field rather than a select, as the select won't take input that isn't already there as fields of that custom form question.
Also, I did not have to use a 'text field' to have the options properly rendered. I was able to populate a select field and it worked. Problem being is that validation fails and it will not actually tell me where (even with error codes) but i suspect its the select field.
Is there a good reason for this happening as the code looks sound...
The form is behind a firewall Nic.
I will have to PM you the login to access the page.