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 »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Prevent default behaviour of form.
Pages: [1]

Author Topic: Prevent default behaviour of form.  (Read 543 times)

VitorFF

  • I post occasionally
  • **
  • Posts: 35
  • Karma: 1
  • CiviCRM version: 4.4.11
  • CMS version: Drupal 7.27
  • MySQL version: 5.5
  • PHP version: 5.4
Prevent default behaviour of form.
October 27, 2014, 03:34:01 am
Hello guys!

I have a form that was built using the buildQuickForm hook and it contains a button that is coded like this:

Code: [Select]
          $this->addButtons(array(
                                  array ( 'type'      => 'next',
                                          'name'      => ts('Save'),
                                          'spacing'   => '         ',
                                          'isDefault' => TRUE   ),
                                  )
                           );

On the same page as the form I have a small text field and an anchor posing as a button.
When the user hits the enter key the action triggered is the anchor click but I'm not being able to prevent the form submit.

I've already tried to change the 'isDefault' property to FALSE but a page reload still occurs.
Also in jquery I've tried using 'return false;' and 'event.preventDefault(); but the form submission still triggers (or the page reload if the isDefault flag is false).

Does any one have a suggestion on how to prevent the default behaviour of a form built using the buildQuickForm hook?

Thank you!

VitorFF
Why don't you take a look at this? (You will not regret it!)

Capitalisation Corrector : https://civicrm.org/extensions/capitalisation-corrector

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Prevent default behaviour of form.
October 27, 2014, 09:32:31 am
When the user hits enter, the browser's default behavior is to submit the form, not click on an anchor.
If you want to prevent this you need to intercept the $form.submit() event and preventDefault on it.
Try asking your question on the new CiviCRM help site.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Prevent default behaviour of form.

This forum was archived on 2017-11-26.