I’m having difficulty using the available formatting options for telephone fields. The user always has to enter the exact format expected, or the text turns red…it’s annoying rather than useful, and doesn’t provide the user with the necessary feedback to complete the field.
I saw the pattern-parsing article by Chris Cain on this topic (Servoy Magazine, 3/1/05). Is that the best current practice (i.e., using a global onDataChange method, and storing the formatting with the number – without providing an entry filter)? To allow for better search results, does anyone store only the numbers in the field? Does anyone have a way to provide the “(###) ###-####” or similar as an entry filter?
Is the Servoy Guy plugin in use with current versions of Servoy? Is it a better solution?
When I try running the wiki sample code (below) on a form button click (Servoy 6.0.eight), I get an error,
ReferenceError: “jsunit” is not defined. (/Users/djlapin/servoy_workspace_20120313/Selpa_Mgr_SQL/forms/student_contact_dd_i.js#211)
ReferenceError: “jsunit” is not defined. (/Users/djlapin/servoy_workspace_20120313/Selpa_Mgr_SQL/forms/student_contact_dd_i.js#211)
at /Users/djlapin/servoy_workspace_20120313/Selpa_Mgr_SQL/forms/student_contact_dd_i.js:211 (testFormatter)
I’m not sure what I am doing wrong. Do you have a sample of how to implement the type-ahead, and is this done with onAction or onDataChange, with a field or some other entry object? Also, are you storing just the numbers or the formatted strings?
I experimented further (stripping out the jsunit stuff). I tried running onDataChange on a data entry field (stc_telephone_3), with my own code –
/**
* Handle changed data.
*
* @param {String} oldValue
* @param {String} newValue
* @param {JSEvent} event the event that triggered the action
*
* @returns {Boolean}
*
* @properties={typeid:24,uuid:"7FECB2FE-7143-4BF2-902B-0670AB8D6DC9"}
*/
function onDataChange_stc_telephone_3(oldValue, newValue, event) {
var phoneObject = plugins.argosPhoneNumber.newJSPhoneNumberUtil();
try {
var phoneParsed = phoneObject.parse(newValue,"US");
if(phoneObject.isValidNumber(phoneParsed)) {
stc_telephone_3 = phoneObject.format(phoneParsed, ARGOS_PHONE_NUM_FORMAT.NATIONAL);
}
}
catch(err) {
stc_telephone_3 = oldValue;
globals.UTIL_alertDlg("That number does not appear to be valid.","Telephone number entry...",null);
}
return true;
}
It appears to work (it formats the telephone field), but it looks like I have to use the try…catch if the user doesn’t enter enough digits. If I don’t use try…catch, it generates a console error instead of going to my error dialog. If this is the case, what does “isValidNumber” doing for the code?
Also, is the format-as-you-type workable for field entry like this?