From d02e1134497e9225b16df48e49842bce76311464 Mon Sep 17 00:00:00 2001 From: Shawn Kwang Date: Tue, 19 Feb 2019 12:07:29 -0600 Subject: [PATCH] Drupal: Added javascript to toggle submit button. On terms-of-use form, added javascript which will disable the Submit (Yes) button if the "do you agree..." checkbox is not checked. Form will work with non-JS enabled browsers as well, the submit button will work, but if the checkbox is not checked, the form will return an error. https://dev.gridrepublic.org/browse/DBOINCP-469 --- .../boinc/modules/boincuser/boincuser.js | 17 ++++++++++ .../boincuser/includes/boincuser.forms.inc | 31 ++++++++++++------- 2 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 drupal/sites/default/boinc/modules/boincuser/boincuser.js diff --git a/drupal/sites/default/boinc/modules/boincuser/boincuser.js b/drupal/sites/default/boinc/modules/boincuser/boincuser.js new file mode 100644 index 0000000000..cf6dbe73fc --- /dev/null +++ b/drupal/sites/default/boinc/modules/boincuser/boincuser.js @@ -0,0 +1,17 @@ +// Javascript for disabling the submit button, enables it when +// terms-of-use checkbox is checked. + +$(document).ready(function() { + // Disable submit on initial page load + $("#edit-submit").attr("disabled", "disabled"); + // On checkbox change, enable submit button + $("#edit-termsofuse-agreeTOU").change(function () { + if ($("#edit-termsofuse-agreeTOU").is(":checked")) { + // enable submit + $("#edit-submit").removeAttr("disabled"); + } else { + // disable submit + $("#edit-submit").attr("disabled", "disabled"); + } + }) +}); diff --git a/drupal/sites/default/boinc/modules/boincuser/includes/boincuser.forms.inc b/drupal/sites/default/boinc/modules/boincuser/includes/boincuser.forms.inc index c614a5c116..227f315d59 100644 --- a/drupal/sites/default/boinc/modules/boincuser/includes/boincuser.forms.inc +++ b/drupal/sites/default/boinc/modules/boincuser/includes/boincuser.forms.inc @@ -697,40 +697,49 @@ function boincuser_termsofuse_form() { drupal_set_message( bts('WARNING: You have not agreed to our terms of use. Please agree to the terms of use before continuing.', array(), NULL, 'boinc:termsofuse-form'), 'warning' ); $form = array(); - - // Terms of use section + drupal_add_js(drupal_get_path('module', 'boincuser') . '/boincuser.js'); $termsofuse = variable_get('boinc_weboptions_termsofuse', ''); - $form['title1'] = array( + + // Fieldset to hold all of the form as a container + $form['termsofuse'] = array( + '#type' => 'fieldset', + '#prefix' => '
', // This is our wrapper div. + '#suffix' => '
', + '#tree' => TRUE, + ); + + $form['termsofuse']['title1'] = array( '#weight' => -12, '#value' => '

' . bts( variable_get('boinc_weboptions_registrationtitle', 'Please read and acknowledge our terms of use'), array(), NULL, 'project:termsofuse-form' ) . '

', '#prefix' => '
', '#suffix' => '
', ); - $form['termsofuse'] = array( + // Terms of use section + $form['termsofuse']['body'] = array( '#weight' => -10, '#value' => bts($termsofuse, array(), NULL, 'project:termsofuse-form'), '#prefix' => '
', '#suffix' => '
', ); - $form['agreeTOU'] = array( - '#type' => 'checkbox', - '#title' => bts(variable_get('boinc_weboptions_agreequestion', 'Do you agree with the above terms of use?'), array(), NULL, 'project:termsofuse-form'), + $form['termsofuse']['agreeTOU'] = array( + '#type' => 'checkbox', + '#title' => bts(variable_get('boinc_weboptions_agreequestion', 'Do you agree with the above terms of use?'), array(), NULL, 'project:termsofuse-form'), '#weight' => -8, '#prefix' => '
', '#suffix' => '
', ); - $form['spacer'] = array( - '#prefix' => '
', + $form['termsofuse']['spacer'] = array( + '#prefix' => '
', '#value' => ' ', '#suffix' => '
', ); // Form Control $form['submit'] = array( - '#prefix' => '

  • ', + '#prefix' => '

  • ', '#type' => 'submit', '#value' => bts('Yes', array(), NULL, 'boinc:form-submit'), '#suffix' => '
  • ', @@ -756,7 +765,7 @@ function boincuser_termsofuse_form() { function boincuser_termsofuse_form_validate($form, &$form_state) { // Check TOU agreement - if (!$form_state['values']['agreeTOU']) { + if (!$form_state['values']['termsofuse']['agreeTOU']) { form_set_error('termsofuse', bts('ERROR: You must acknowledge our terms of use by clicking the checkbox before registering for an account.', array(), NULL, 'boinc:termsofuse-form')); } }