Forum Stats

  • 3,855,344 Users
  • 2,264,499 Discussions
  • 7,905,975 Comments

Discussions

Save a phone number without the input mask

997866
997866 Member Posts: 21
edited Apr 11, 2013 2:33PM in APEX Discussions
Hi,

I actually have 2 related issues that I hope you might be able to help me with.

I have a form linked to an interactive report, so when I click a record, the form is populated with the record's data. I just started using the new text field masked input plugin to handle phone number formatting, etc., which Patrick recommended.

The plugin works nicely when a phone number being displayed from the source is 10 characters. The input mask I'm using is (999) 999-9999. However, I also have phone numbers in records that don't include the area code. When I select one of those records, the phone number field is blank. I would like it to display 999-9999, and be right justified. Is there an easy fix for that?

My next problem occurs when I try to save the record. The process tries to save the phone number, including the mask, (14 characters), to the table. I only want to save the number to the table, excluding the mask. I'm sure there is a way to do this but I haven't found it yet.

Thanks in advance for any help,

Gary
«13

Answers

  • Howard (... in Training)
    Howard (... in Training) Member Posts: 905
    edited Apr 9, 2013 3:08PM
    You don't say what plugin this is or what thread Patrick mentioned it in. But regardless, what does the plugin's documentation say? Are there other masks that handle/suppress leading zeros or blanks?

    My thinking on your second question is this. I don't want to have to parse out the formatting, so I would NOT format the page item for the number with the plugin. I'd hide the page item (column) I intended to save back to the DB. Then I would make a copy (derived column) to pass to the plugin and display that.

    Howard
  • 997866
    997866 Member Posts: 21
    Howard,

    Thanks for getting back. I'm using this: masked_field_v_1_0 by Josh Bush. There is only the installation instructions and the example mask of 999-999-9999. There may be other doc on JB's page. I'll check into that.

    As for your suggestion that I should hide the page item and not mask it, then display a copy. I could do that, in fact, I considered doing it, but I don't just need to display the pn, I also need to be able to edit it as well. So my question remains: How to I pass just the number value on to my hidden field after typing it in the masked input field?

    Thanks for your quick response and your suggestions.

    Regards,

    Gary
  • Howard (... in Training)
    Howard (... in Training) Member Posts: 905
    edited Apr 9, 2013 4:06PM
    It's never that simple, is it?

    Some possibilities. 1) We have to parse. So whenever the plugin item changes in the derived column, parse the plugin formatted value, validate it and copy it into the hidden item. You validate the value so you know you always have a valid value in the DB related item.

    2) Now there may be a way to display one value (formatted) but save another (unformatted). But can this be done with just one page item? I'll have to look into it. (Does the plugin use the same page item for input and output. Does it actually change the item? If so, you need something like: If rendering, use plugin formatted value but if Submitting, parse out formating before saving.)

    Howard

    Edited by: Howard (... in Training) on Apr 9, 2013 4:04 PM
  • Howard (... in Training)
    Howard (... in Training) Member Posts: 905
    edited Apr 9, 2013 4:16PM
    For number 2), where one uses a single page item, the one to be saved back to the database. How about:

    1. The item starts with the unformatted value.
    2. When the page renders, the plugin is invoked to change the item value.
    3. So the formatted item value is displayed.
    4. Changes are made and those could be validated when the item loses focus.
    5. Two actions are invoked Submit is clicked:
    a. The item is validated and parsed and changed to it's unformatted value.
    b. The page is Submitted with this item unformatted.
    6. If the page re-renders, we are back to number 1. above.

    Would that have a prayer of working?
    Howard
  • Re:
    How to I pass just the number value on to my hidden field after typing it in the masked input field?
    You need code to manipulate the value -- validate and parse out the formatting -- and set this value into the hidden item. I presume that this could be done in a PL/SQL block in a Dynamic Action.

    Are you comfortable with Dynamic Actions? DAs have a triggering event which could be a change to the formatted item. Or perhaps onblur() when the cursor moves from the formatted item to another item or Submit is clicked.

    Howard
  • 997866
    997866 Member Posts: 21
    Hi Howard,

    If I understand this correctly, it may work, provided you can change the type of item programatically upon rendering the page. The item is of type "plugin" or some such that I created using the wizard as JB instructed. So, if we could set the item to be "text" and then to "plugin" on page render, that might do it. I think the on_blur option may work to call a javascript function to validate and parse. I will need to look into that. I'll let you know more after I do further research.

    Thanks!

    Gary
  • 997866
    997866 Member Posts: 21
    Ok, I've been trying a few things, so far, none are working.

    I created a javascript function in my page header to test this. The idea was to strip the mask characters from the number and assign the result to a hidden field.

    function remmask(P4_PHONE){
    var mystring = $x('PHONE').value;
    myString = myString.replace/^\D+/, '');
    $x('P4_PHONE').value = mystring;
    }

    I then put the call in the form element attributes of the PHONE field, (the one with the mask):

    onBlur="javascript:remmask('P4_PHONE');"

    The function fires but I'm getting a page error. I tried replaceing the regex with a simple string value of 'test' and I still get the error. Any suggestions?

    Regards,

    Gary
  • 997866
    997866 Member Posts: 21
    Yes, I know I was missing the left "(" in the replace. But this simple test didn't work either:

    function f_setItem (P4_PHONE)
    {
    var pValue='test';
    $x('P4_PHONE').value = pValue;
    }
  • 997866
    997866 Member Posts: 21
    I did get the test to work. The error is in this part:

    myString = myString.replace(/[^\d.]/g, "");

    I am not sure why this isn't working. If I remove it, the rest of the code works, placing the number, and the mask, in the target.


    function remmask(P4_PHONE){
    var mystring = $x('PHONE').value;
    myString = myString.replace(/[^\d.]/g, "");
    $x('P4_PHONE').value = mystring;
    }
  • Howard (... in Training)
    Howard (... in Training) Member Posts: 905
    edited Apr 10, 2013 4:14PM
    For my grief with Hidden Items see: {thread:id=2523124}

    How about some baby steps? When debugging I like to go step by step.
    1) I'd try it first with a non-hidden item so I could see exactly what values are being used. After that is mastered, then move to a hidden item.
    2) How about a very trivial function that just assigns the value without removing anything or concatenates a '1'. Something trivially simple so we see if this approach can ever work.
    3) Run the regular expression replace code -- suitably formatted -- in a SELECT statement in SQL Developer or SQLPlus or APEX SQL Commands, to make sure it does what you want.

    My 2 cents,
    Howard
This discussion has been closed.