CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • How to make event registration fields conditionally required
Pages: [1]

Author Topic: How to make event registration fields conditionally required  (Read 383 times)

narayanis

  • I post occasionally
  • **
  • Posts: 56
  • Karma: 2
How to make event registration fields conditionally required
September 03, 2014, 06:43:48 am
We've set up an event registration with a price set. Field 'Foo' is a radio with multiple price options; this field is not required so we have the -none- option at the end. Another optional price set field ('Bar') allows the user to set any registration amount. It is an integer field with the price set to $1; so if the user types 20, the registration amount is $20.

If the user selects -none- from price list 'Foo', we want to make 'Bar' required. Are there any examples that show a simple way to go about this? I thought I could use built-in jQuery validation by adding the below code to Register.extra.tpl. However, while it adds/removes the class, it doesn't seem to enforce anything.

Code: [Select]
var myAmount = $("label[for='" + $('#CIVICRM_QFID_0_14').attr('id') + "']");
$(myAmount).text("I will set my own amount");


$('input:radio').change(
    function(){

if ($('#CIVICRM_QFID_0_14').is(':checked'))
{
$('#price_44').addClass('required');
}
else
{
$('#price_44').removeClass('required');
}
    }
);

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: How to make event registration fields conditionally required
September 04, 2014, 01:21:47 am
Adding the classes won't do anything - since the underlying PHP does not get informed of the change.

Another approach would be to use jquery to disable / hide the submit button, and or replace it with some text which explains what the user needs to do to get it enabled again. ("Since you have selected  -none- from price list 'Foo', you need to add something to 'Bar'") or similar.

HTH

Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

narayanis

  • I post occasionally
  • **
  • Posts: 56
  • Karma: 2
Re: How to make event registration fields conditionally required
September 04, 2014, 10:39:56 am
Thanks Michael; I saw /templates/CRM/Form/validate.tpl, and thought perhaps its presence meant that jQuery validation was commonly available to all forms. I'll take your advice and disable the button.

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: How to make event registration fields conditionally required
September 05, 2014, 02:38:10 am
NP feel free to post code here once completed for other people's edification :)
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • How to make event registration fields conditionally required

This forum was archived on 2017-11-26.