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) »
  • Improvements to js for custom data for contact sub types on contact edit screen
Pages: [1]

Author Topic: Improvements to js for custom data for contact sub types on contact edit screen  (Read 489 times)

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
Improvements to js for custom data for contact sub types on contact edit screen
May 30, 2012, 11:11:18 am
Hey there,

I was coming across a problem with a client civicrm where you couldn't select a contact subtype for an individual.  These occurs when there is only one contact subtype.

It seems the offending bit of code is in Contact/Form/Edit/Individual.tpl:

Code: [Select]
if (cj('#contact_sub_type *').length ==1) {//if they aren't any subtype we don't offer the option
   cj('#contact_sub_type').parent().hide();
}
The effect of this code is to hide the contact subtype box when there *is one* subtype, which in my opinion doesn't make sense because if you have one subtype then you have two types: plain old individual and the subtype you defined.  Since you might want to say that your current contact is either of these, it is better to leave this box exposed.  Otherwise, there is no way to turn your contact into the contact subtype when you only have one sub type defined.

So I removed that code.

I also had a look at the code that attaches the hiding and showing custom data for the contact.  For some reason there was a removeCustomData = true variable set to ensure that removeDefaultCustomFields( ) was only being run once.  That doesn't make any sense to me since if you go from a contact sub type with custom data to a contact without custom data, then you want to remove the Default Custom Fields, no?

So I removed it.  I am not sure how you go about working out why that code is in there but I am guessing you could use fisheye to do that.  I'm sure there is / was a reason and I'm curious to know what that was.

The other thing I did was move the javascript from the Form (onChange=) to the template (.click()) which seems like a better way to call this, and *I think* it behaves better with multiselects when you unselect all options.

Well, this works for my client.  Here are links to two git diffs that describe what I did.

https://github.com/michaelmcandrew/ff/commit/9e8eaa0286bdb894a26e68776865152c98b62fcb
https://github.com/michaelmcandrew/ff/commit/7a59e1b7e531ce230029db42b9368293a16ce7f7

I could attach the to an issue if people think that is a good idea.

I am also up for trying to discover why the code was like it was in the first place since I might be overlooking something

Michael


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) »
  • Improvements to js for custom data for contact sub types on contact edit screen

This forum was archived on 2017-11-26.