Function pika phone

From PikaDocs

The function pika_phone is what fills in a dash in the phone number for you after typing 3 digits. I don't know who gets the credit for drawing it up - was it the Pika User Experience Gurus (http://www.openpika.org/archives/2006/04/pika_tooltips_o.html) or the programmers at Pika Software (http://www.pikasoftware.net/)?

We ran into a bit of a problem. Our screeners are used to typing in the dash, many of them in fact have been doing that every day in our current CMS for over a decade. It's a big change in their efficient habits to stop typing that dash. But they end up typing 3 digits, have a dash automatically added, then type another dash. On with the phone number they continue and they type 3 more digits and run out of room in the field with a phone number like 863--562.

However, adding the dash is a good usability tip for new users of the CMS, and just in general seems like a good practice for data consistency.

I decided to try to rewrite the function a little bit to see if I could solve the problem while still retaining the advantages of having the dash added.

Here's the old one:

function pika_phone(what)
{
	if (what.value.length == 3 && old_phone_length == 2)
	{
		what.value += '-';
	}

	old_phone_length = what.value.length;
}

Here's the new one:

function pika_phone(what)
{
       if (what.value.length == 3 && old_phone_length == 2)
           what.value += '-';
       else if (what.value.length == 5 && what.value.charAt(3)=='-' && what.value.charAt(4)=='-')
           what.value = what.value.substring(0,4);
        
       old_phone_length = what.value.length;
}

What did I do? Well, I:

  • removed the brackets for the first condition. I thought that might speed things up a bit. Maybe it won't but I figured it wouldn't hurt to take them out - they aren't needed and this is one bit of code where speed really might matter.
  • added a new condition to check if the phone number string is 5 characters long and has a dash at positions 3 and 4. (Remember that position 0 is where the string begins). So a phone number that looks like 863--.
  • if that 2nd condition is true, cut off the extra dash and stuff the result back into the phone number.

If you try this, type 8 then 6 then 3 then -. You'll notice Pika add a dash after you type 3. After you type your dash, you'll see it backspace over the extra dash.

Subtemplates to change

  • add_matter_contact_list.html
  • case_contact_list.html
  • contact_counsel.html
  • contact_full.html
  • contact_list.html
  • intake_contact_list.html
  • matter_contact_list.html

Is it just me, or are these subtemplates crying out to have their javascript set in an external include file? Well, maybe the rumored demise of subtemplates in Pika 3.06 will take care of this.


original entry by Andrew Cameron
Legal Services Lawline of Vermont (http://www.lawlinevt.org/) and Vermont Legal Aid (http://www.vtlegalaid.org/)