How do I implement conditional fields?

More
02 Jan 2012 23:54 #11 by Demis [Fox-Labs]
Replied by Demis [Fox-Labs] on topic How do I implement conditional fields?
We discussed about this once in past.
I'll try to search the corresponding post on this forum tomorrow.
A used posted modifications do achieve a such behavior.
For the future, I plan to add it to the standard version as soon as I can.

Please Log in or Create an account to join the conversation.

More
18 Jan 2012 05:21 #12 by Laleh
Replied by Laleh on topic How do I implement conditional fields?
Did you find the post of the other user who did this? We are waiting for the solution.

Please Log in or Create an account to join the conversation.

More
18 Mar 2013 13:21 - 18 Mar 2013 13:22 #13 by Alex Curtis
Replied by Alex Curtis on topic How do I implement conditional fields?
Hi all,

Is it possible to have a box appear - so when the user clicks 'Other' on 'How did you hear about us? a box appears underneath labelled other on the left hand side and then they can fill it in.

I currently have just a text box underneath but wondered if there was a way in which you can click other and a box appears underneath just like this : http://demo.cswapps.com/extensions-demos/contact-us-pro.html

I have fox contact 2.5 installed of the website.

Thanks for any help
Alex

Please Log in or Create an account to join the conversation.

More
19 Mar 2013 13:34 #14 by Alex Curtis
Replied by Alex Curtis on topic How do I implement conditional fields?
Hi all,

In the drop down menu section is there a way I can make a box appear below when the user is asked the question - 'How did you hear about us' and chooses 'other'?

Like this example: http://demo.cswapps.com/extensions-demos/contact-us-pro.html

I currently have 2.5 version installed.

I'd appreciate anyone's help!
Kind Regards
Alex

Please Log in or Create an account to join the conversation.

More
19 Mar 2013 23:06 - 20 Mar 2013 00:05 #15 by Graeme Moffat
Replied by Graeme Moffat on topic How do I implement conditional fields?
Something like this :cheer:
Look at that page's source, copy line 154 (the one after the </select>). Change id="hdyhauOtherWrapper" to just "otherWrapper".
Edit /components/com_foxcontact/helpers/fieldsbuilder.php, find the builddropdown() function (sorry, I don't have the code immediately available, so names & example code might not be quite correct), and after the line that will look like:
$result .= '</select>';
add
$result .= '[the copied line, suitably modified]';
Be careful with quotes!
Add a new rule to neon.css:
#otherWrapper {
  display: none;
}
That might need some further tweaking later, if positioning is wrong.

That was easy, now comes the tricky part, which I am unsure of myself :whistle:
Look back at the page source, line 144, where the <select> has an id="hdyhau" and onchange="swap()". The code for this is on lines 204-210:
function swap() {
if(document.getElementById('hdyhau').value == 'Other') {
  document.getElementById('otherWrapper').style.display = 'block';
 } else {
  document.getElementById('otherWrapper').style.display = 'none';
 }
}

FC already has, in fieldsbuiler.php, an onchange="DropdownAlignValue(this)" and also an id="generated_name".
The code in swap() above, (but not the function itself), needs to be added to the javascript in function DropdownAlignValue(). The 'hdyhau' id will have to be automagically provided by the script itself, but this is where my lack of knowledge of OO coding shows. It will be related to the "this" argument in the function call, and looking at the code might provide a very simple clue as to how this (no pun intended) works.
But hey, I need to leave something for you to do :cheer:

NB- I have never looked at FC's javascript, but it's in /components/com_foxcontact/js/

Please Log in or Create an account to join the conversation.

More
20 Mar 2013 15:42 #16 by Alex Curtis
Replied by Alex Curtis on topic How do I implement conditional fields?
Thanks kindly for your help gyroglm was very much appreciated. Looks like a good move to me, will get editing it in today and let you know if it works, sure it will.

I loved your use of examples,detail and humour has made my day and i've only just got up :)

Kind Regards
Alex

Please Log in or Create an account to join the conversation.

More
21 Mar 2013 12:30 #17 by Graeme Moffat
Replied by Graeme Moffat on topic How do I implement conditional fields?
Couple of points that that occurred to me afterwards:
FC uses generated ids/names to presumably allow for multiple copies on the same page, (or perhaps some more obscure reason that is beyond my comprehension :) ), so if you have a hard-coded id (ie otherWrapper) for the div (and of course, also for the input textbox that receives the explanation), you'll have to promise not to have more than one form :ohmy: .

And, that once you've got this field into the form, you have to extract it out into the email. This happens in two places (fsubmittermailer.php & fdispatcher.php, I think) in helpers. The functions in fdispatcher are 'body' and 'AddToBody' which depend on the method 'FieldsBuilder' and property 'Fields' . The dropdown's value itself will be 'Other', you'll need to work out how to extract the 'other' text itself and include it.

This might also have to tie in with the XML file that defines the form, you may have to define a hidden field in there, so that fieldsbuilder.php can add it in to the 'Fields' list - I really don't know. What I do know is that what started off sounding quite straightforward seems to be getting more complicated - but that's the challenge.

and i've only just got up

Thinking about this is giving me quite a headache, so I'd really like to go to bed :(
The following user(s) said Thank You: Alex Curtis

Please Log in or Create an account to join the conversation.

More
06 May 2013 13:39 #18 by Alex Curtis
Replied by Alex Curtis on topic How do I implement conditional fields?
Thanks for all your vast help Gyroglm,

Truly appreciate it, however I gave up on this programming adventure due to my lack of experience, hopefully this can be integrated later on in updates cross fingers.

Kind Regards
Alex

Please Log in or Create an account to join the conversation.

More
07 May 2013 00:46 #19 by Demis [Fox-Labs]
Replied by Demis [Fox-Labs] on topic How do I implement conditional fields?
I remember that a long time ago an user published here his customizations: one field is shown based on the dropdown selection.
Unfortunately, after a deep search, I am unable to find that post.
I found that the question has been raised a few times again, so I gathered all that posts in the same thread.

You should write your own javascript which shows/hide your field based on the selected item.
The following user(s) said Thank You: Alex Curtis

Please Log in or Create an account to join the conversation.

More
10 Nov 2013 03:03 #20 by Robert Gilbey
Replied by Robert Gilbey on topic How do I implement conditional fields?
Please refer to http://www.ultravolt.com/customer-service

How do I create a conditional field called State that is triggered if United States is selected from Country dropdown? Version used is 2.5.6

Thank you.
The following user(s) said Thank You: pieni sieni

Please Log in or Create an account to join the conversation.