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) »
  • Making out-of-the-box fields required/compulsory
Pages: [1]

Author Topic: Making out-of-the-box fields required/compulsory  (Read 865 times)

Simon West

  • I’m new here
  • *
  • Posts: 19
  • Karma: 1
  • CiviCRM version: 44311
  • CMS version: Drupal 7
  • MySQL version: 5.5.9
  • PHP version: 5.3.6
Making out-of-the-box fields required/compulsory
January 09, 2014, 10:06:09 am
Hi,

There was a post in 2012 suggesting use of the buildhook and javascript for validation. Could someone confirm whether this is possible, please? And is there an alternative to this which would not require 'hacking' the core? If not, is there appetite for doing this in the UI, if I haven't overlooked it?

Thanks!
Simon


Use case:
A care provider is using CiviCase to document the case history of a client. They have 1-2-1 therapy with their clients on a regular basis, amongst other intervention methods like training and group meetings. The organisation wishes to report on the time they spend on each type of intervention across a large sample of their clients, and through inferential statistics attempt to find evidence suggesting that more of a given type of intervention achieves stronger results. Other potential confounding factors aside, they will initially export and take into account data on:

  • the total number of each intervention (CiviCase activity) per client
  • the total/average time spent on each of those activities, through the duration field (in minutes); the intervention duration varies

If the duration field cannot be flagged as a required field, and staff accidentally forget to complete it, the statistics would be skewed.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Making out-of-the-box fields required/compulsory
January 09, 2014, 11:49:10 am
Hi Simon - had a quick chat about this w/ Coleman and we think the simplest approach is to use the .extra.tpl mechanism to implement client side validation on that form field. I'm doing quick experiment here now since I wanted to see this 'in action'. I'll post back shortly w/ details.
Protect your investment in CiviCRM by  becoming a Member!

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Making out-of-the-box fields required/compulsory
January 09, 2014, 01:53:44 pm
Here's the client-side validation approach which I tested. Seems pretty good ...

1. Define a Custom Templates path for the site (if you haven't already).
Administer > System Settings > Directories

2. Create a new file called Activity.extra.tpl a put this code in it:
Code: [Select]
{include file="CRM/Form/validate.tpl"}
{literal}
<script type="text/javascript">
cj( function( ) {
  cj('#duration').addClass('required digits');
});
</script>
{/literal}

3. Place the file under your custom templates directory in CRM/Activity/Form/Activity folder (replicates the location of the core activity form template - but in your custom templates tree).

Users will now get a friendly validation error if they either leave duration blank OR enter something other than digits. If you'd rather allow them to enter any number (e.g. 20.5) then change 'digits' to 'number'.

Screenshots show the behavior when user leaves field blank or enters invalid data.
Protect your investment in CiviCRM by  becoming a Member!

Simon West

  • I’m new here
  • *
  • Posts: 19
  • Karma: 1
  • CiviCRM version: 44311
  • CMS version: Drupal 7
  • MySQL version: 5.5.9
  • PHP version: 5.3.6
Re: Making out-of-the-box fields required/compulsory
January 10, 2014, 02:53:52 am
Fantastic! I'll try it out later. Very kind of you to put this together - I really appreciate it.

A quick question off the back of that: could this be invoked by activity type selected? Would that be too complicated? Activities are quite versatile, and the duration field might not be applicable to all custom activities. From a user perspective, I imagine entering "0" might be a little irritating if you're entering activities manually on a regular basis.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Making out-of-the-box fields required/compulsory
January 10, 2014, 06:51:17 pm
Pretty sure you could add that. You'd need additional jQuery logic which controls whether the "required" class is added or not based on the selected value of the Activity Type dropdown.
Protect your investment in CiviCRM by  becoming a Member!

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: Making out-of-the-box fields required/compulsory
January 12, 2014, 02:30:27 pm
given you are using drupal did anyone consider using a webform as your way of getting the users to add data, and you could 'require' the field on the webform rather than getting tricky with civi
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

Simon West

  • I’m new here
  • *
  • Posts: 19
  • Karma: 1
  • CiviCRM version: 44311
  • CMS version: Drupal 7
  • MySQL version: 5.5.9
  • PHP version: 5.3.6
Re: Making out-of-the-box fields required/compulsory
January 13, 2014, 02:16:36 am
Cheers Dave.

Petednz, good shout. This org is editing existing activities inside of a case (created by a timeline), and referring to other data elsewhere in the case record, so a webform wouldn't quite work out, but they are using them for other things (internal referral processing, etc).

For others finding this thread, Pete's suggestion is definitely possible :)

Thanks guys!

Simon West

  • I’m new here
  • *
  • Posts: 19
  • Karma: 1
  • CiviCRM version: 44311
  • CMS version: Drupal 7
  • MySQL version: 5.5.9
  • PHP version: 5.3.6
Re: Making out-of-the-box fields required/compulsory
January 14, 2014, 03:49:05 am
Also, for anyone reading this thread and also trying to use template above for validating activity fields, there are two different activity templates: one for activities against the contact record, and another for activities created/filed inside cases.

Paths for each activity template:

Contact activities: CRM/Activity/Form/Activity.tpl
Case activities: CRM/Case/Form/Activity.tpl


Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • Making out-of-the-box fields required/compulsory

This forum was archived on 2017-11-26.