Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 09-12-2014, 02:07 AM
marianoaran marianoaran is offline
 
Join Date: Jun 2013
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default User Profile Fields - Conditional fields

Hello,

I've done a search but can't seem to find any info about this.

We need to collect some information in the registration form according to the type of user registering.

To make registration easier (and shorter), we thought of including some conditional questions like:

1) Are you a health professional? YES ( ) NO( )
a) if YES - Then further questions
b) if NO - move on to next question.

(1) would be required
(a) and (b) would be required only if (1) is YES

Is there any mod that can do this?

thanks!
Reply With Quote
  #2  
Old 09-12-2014, 02:08 AM
ozzy47's Avatar
ozzy47 ozzy47 is offline
 
Join Date: Jul 2009
Location: USA
Posts: 10,929
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Not that I have seen, it would need to be custom coded.
Reply With Quote
  #3  
Old 09-12-2014, 05:16 AM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I made a little JavaScript script that can do this. I need a link to your forum and a description of the field with the Yes button and the fields you want to show upon clicking so I can get the element id's
Reply With Quote
2 благодарности(ей) от:
Lynne, marianoaran
  #4  
Old 09-12-2014, 05:48 AM
marianoaran marianoaran is offline
 
Join Date: Jun 2013
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hey nerbert thanks so much for helping out!

Just PMed you :-)
Reply With Quote
  #5  
Old 09-12-2014, 06:11 AM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Here's the plugin I made for "register_form_complete" hook location

Code:
$customfields_profile .= "
	<script>
		fetch_object('cfield_5').parentNode.parentNode.style.display = 'none';
		YAHOO.util.Event.on(window, 'click', function(e) {
			var radio = YAHOO.util.Event.getTarget(e)
			if(radio.id == 'rb_cpf_field6_1') {
				fetch_object('cfield_5').parentNode.parentNode.style.display = 'block';
			}
			if(radio.id == 'rb_cpf_field6_2') {
				fetch_object('cfield_5').parentNode.parentNode.style.display = 'none';
			}
		});
	</script>
";
cfield_5 is the id of a text input field that appears only upon clicking the yes button

rb_cpf_field6_1 is the id of the Yes button

rb_cpf_field6_2 is the id of the No button


You can set several fields to change display

--------------- Added [DATE]1410533632[/DATE] at [TIME]1410533632[/TIME] ---------------

I just thought of something -- if you set all these fields to "required" the form won't submit with the conditional fields left blank. Here's code that will fill in the fields if they're hidden

Code:
$customfields_profile .= "
	<script>
		fetch_object('cfield_5').parentNode.parentNode.style.display = 'none';
		fetch_object('cfield_5').value = 'NOT APPLICABLE';
		YAHOO.util.Event.on(window, 'click', function(e) {
			var radio = YAHOO.util.Event.getTarget(e)
			if(radio.id == 'rb_cpf_field6_1') {
				fetch_object('cfield_5').parentNode.parentNode.style.display = 'block';
				fetch_object('cfield_5').value = '';
			}
			if(radio.id == 'rb_cpf_field6_2') {
				fetch_object('cfield_5').parentNode.parentNode.style.display = 'none';
				fetch_object('cfield_5').value = 'NOT APPLICABLE';
			}
		});
	</script>
";
Reply With Quote
2 благодарности(ей) от:
Lynne, tbworld
  #6  
Old 09-16-2014, 10:19 PM
marianoaran marianoaran is offline
 
Join Date: Jun 2013
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks so much for your help nebert! This works great in 'almost' all browsers.

In IE8 the hidden fields are not displaying. The strange thing is that console is not giving me any errors... it's just ignoring the selection of different options and not showing any hidden field.

Any ideas on what can this be?

I also tried with IE9 in IE8 compatibility mode and it behaves in the same way.
Reply With Quote
  #7  
Old 09-17-2014, 02:40 AM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Maybe you don't want IE8 types on your forum??????

Well I thought the whole point of all that YAHOO code was browser compatibility. So here's doing it the old fashioned way:

Code:
$customfields_profile .= "
	<script>
		fetch_object('cfield_5').parentNode.parentNode.style.display = 'none';
		fetch_object('cfield_5').value = 'NOT APPLICABLE';
                if(document.addEventListener)  document.addEventListener('click', openFields, true);
                else if(document.attachEvent)  document.attachEvent('onclick', openFields);

		function openFields(e) {
			var radio =  e.srcElement || e.target ;
			if(radio.id == 'rb_cpf_field6_1') {
				fetch_object('cfield_5').parentNode.parentNode.style.display = 'block';
				fetch_object('cfield_5').value = '';
			}
			if(radio.id == 'rb_cpf_field6_2') {
				fetch_object('cfield_5').parentNode.parentNode.style.display = 'none';
				fetch_object('cfield_5').value = 'NOT APPLICABLE';
			}
		}
	</script>
";
--------------- Added [DATE]1410966671[/DATE] at [TIME]1410966671[/TIME] ---------------

There's one thing you may wish to consider before changing the code. I think by default vBulletin gets its YUI (Yahoo! User Interface Library) remotely from Google or Yahoo servers. You can change that to local hosting in

Server Settings and Optimization Options > Use Remote YUI = "None"

Getting it remotely is supposed to save bandwidth but I've had trouble with connection failures before.

But the point here is that apparently remotely hosted YAHOO no longer supports IE8 (I think I heard jQuery quit too) but I'm sure your locally hosted vB version still does.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:14 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06354 seconds
  • Memory Usage 2,230KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (4)post_thanks_box_bit
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete