Phone Field Renderer

  • 1
  • Question
  • Updated 4 years ago
  • Answered
I am trying to make a phone renderer like the built in one for SF and I need some help to make it work fully. I have the below snippet that works but only when the field editor is Read-withInlineEditing and it does not work when the Field Editor is just Edit mode. I need to get that fixed but also, How can I make the transformed text be what is actually saved and not what was actually typed in? Ex. I type in Phone # 123-4567777 and that gets saved I want it to actually save as (123) 456-7777

Here is my Field Renderer code that works on InlineEdit only and only transforms the view of the field not the saving of the data:

var field = arguments[0], value = arguments[1];    
// use substring to get at the values...

if(value !== null){
     var origstringValue = value.toString();
     var stringValue = origstringValue.replace("-", "");
     stringValue = stringValue.replace("(", "");
     stringValue = stringValue.replace(")", "");
     stringValue = stringValue.replace(" ", "");
     stringValue = '(' + stringValue.substring(0,3) + ')' + ' ' + stringValue.substring(3,6) + '-' + stringValue.substring(6,10);
     if (stringValue == '() -'){
         stringValue = '';
     }
}

skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,stringValue);
Photo of Jarrod Hinson

Jarrod Hinson

  • 2,310 Points 2k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
Photo of Jarrod Hinson

Jarrod Hinson

  • 2,310 Points 2k badge 2x thumb
ok, I tried this, still not working. The page wont load still. I looked in Ctrl+Shift+J in Chrome and it doesn't show anything that I can tell from the snippet, maybe I am not looking in the right place.
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
Must be another issue then... If you don't see any errors in the console then I can't explain it.
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Jarrod, you might want to back up to square one.  Get all the custom javascript out of your page and then make sure it loads.  After you have success there - then start adding resources back  one at a time.  When it breaks - you know you have a culprit. 
Photo of Jarrod Hinson

Jarrod Hinson

  • 2,310 Points 2k badge 2x thumb
as soon as i comment out this line the page works fine. Except my phone field value doesn't get updated.

field.model.updateRow(field.row,'PersonMobilePhone',stringValue,{initiatorId: field._GUID});
Photo of Jarrod Hinson

Jarrod Hinson

  • 2,310 Points 2k badge 2x thumb
as soon as i comment out this line the page works fine. Except my phone field value doesn't get updated.

field.model.updateRow(field.row,'PersonMobilePhone',stringValue,{initiatorId: field._GUID});