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) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • Add JavaScript Attribute to Custom Data Text Field
Pages: [1]

Author Topic: Add JavaScript Attribute to Custom Data Text Field  (Read 2871 times)

rs3515

  • I’m new here
  • *
  • Posts: 29
  • Karma: 1
Add JavaScript Attribute to Custom Data Text Field
May 06, 2008, 02:17:26 am
I'd like to add an onBlur attribute to a CiviCRM custom text field.  Is there a way I can set an attribute in one of the template files?  Or maybe write some code in a core Form.php file? 

I wondered if an option could be to grab the field's HTML from the $customPost array and perform a str_replace to change "<input" to "<input onBlur='....'"?  I'm not sure the right place where I would need to do something like this or the right way to access it from CiviCRM's array.

Any advice would be appreciated.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Add JavaScript Attribute to Custom Data Text Field
May 06, 2008, 04:16:41 am

you should check: CRM/Core/BAO/CustomField.php, function addQuickFormElement

QuickForm can take a 'attributes' argument which it copies into the input element (search for attributes in that function)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

rs3515

  • I’m new here
  • *
  • Posts: 29
  • Karma: 1
Re: Add JavaScript Attribute to Custom Data Text Field
May 06, 2008, 07:32:18 am
Just so I understand, the suggestion is to build a custom input field on the page using addQuickFormElement, and pass to it what attributes it should have?

This is for a CiviCRM field that is already standard on the main CiviContribute page.  Does it make sense to rebuild a field that already exists in core or will I run into other problems?

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Add JavaScript Attribute to Custom Data Text Field
May 06, 2008, 12:41:49 pm
That function actually creates the custom fields which have been "assigned" to a given form. Since you have a custom field on that form, I think the suggestion is to modify the function to add your onblur attribute for a specific instance of a custom field (probably using a conditional on the $elementName or $label value).
Protect your investment in CiviCRM by  becoming a Member!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • Add JavaScript Attribute to Custom Data Text Field

This forum was archived on 2017-11-26.