Phone Field Renderer

edited September 1, 2016 in Questions
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);

Comments

  • edited January 12, 2015
    Thats where I got my starting snippet above, that piece works great but I need it to actually save the modified String Value and it would be nice if it worked in Edit Mode as well. Ideas?
  • edited January 12, 2015
    OK before the fieldRenderers line, add the following line:
    field.model.updateRow(field.row,'Your_Custom_Field__c',stringValue,{initiatorId: field._GUID});
  • edited January 12, 2015
    Is there a way for it to get the Custom field name from field.? I would then have to make copies of the whole snippet for each phone field I need to use this for then?
  • edited January 12, 2015
    Try:
    console.log(field);
    and see if you find the API name in there somewhere...
  • edited February 2, 2015
    I tried this but it is not working, the page won't display when I add this. I would like to either strip all characters and save that value so if the user enters 111-444-5555 it saves 1114445555 and renders (111) 444-5555

    I tried just putting in my custom field name manually and it still does do anything the page wont load using this?

    field.model.updateRow(field.row,'Your_Custom_Field__c',stringValue,{initiatorId: field._GUID});
  • edited February 3, 2015
    Can you post your full snippet here? 
  • edited February 3, 2015
    var phonefield = arguments[0],    phonevalue = arguments[1];
    // use substring to get at the values...

    if(phonevalue !== null){
         var origstringValue = phonevalue.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 = '';
         }
    }
    field.model.updateRow(field.row,'PersonMobilePhone',stringValue,{initiatorId: field._GUID});
    skuid.ui.fieldRenderers[phonefield.metadata.displaytype][phonefield.mode](phonefield,stringValue);
  • edited February 3, 2015
    Try replacing this line:
    field.model.updateRow(field.row,'PersonMobilePhone',stringValue,{initiatorId: field._GUID}); 
    with this:
    field.model.updateRow(field.row,'PersonMobilePhone',phonevalue,{initiatorId: field._GUID}); 
    Also, I'm assuming that the API name of "PersonMobilePhone" is correct and it's not "Person_Mobile_Phone__c" or something. Out of curiosity what type of field is PersonPhoneMobile?
  • edited February 3, 2015
    its a standard field in SF for PersonContact, I also tried another custom phone field.
  • edited February 3, 2015
    So basically it's a standard "Phone" field, I think that's a number field so it should be able to be saved. Did you try adjusting the snippet as I suggested above?
  • edited February 3, 2015
    Yea it does the same thing. the page doesn't load at all.
  • edited February 3, 2015
    I see what you're issue was... try this instead:
    var field = arguments[0],    phonevalue = arguments[1];// use substring to get at the values...
    if(phonevalue !== null){
         var origstringValue = phonevalue.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 = '';
         }
    }
    field.model.updateRow(field.row,'PersonMobilePhone',stringValue,{initiatorId: field._GUID});
    skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,stringValue);
  • edited February 3, 2015
    Basically you changed the first variable to "phonefield" but the rest of the snippet was assuming it was named "field". If you open the Javascript console (Ctrl + Shift + J in Chrome) you'll probably see an error like "field is undefined" or something. I just changed it back to "field" instead of "phonefield". 
  • edited February 3, 2015
    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.
  • edited February 3, 2015
    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.
  • edited February 3, 2015
    Must be another issue then... If you don't see any errors in the console then I can't explain it.
  • Rob HatchRob Hatch 💎💎💎
    edited September 1, 2016
    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. 
  • edited February 3, 2015
    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});
  • edited February 3, 2015
    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});
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!