Hello Wei Hong,
If you want only 1 phone field and you know exactly key I suggest you yo use my code because it is easier and faster:
Code:Only registered members can view the code.
Hello Wei Hong,
If you want only 1 phone field and you know exactly key I suggest you yo use my code because it is easier and faster:
Code:Only registered members can view the code.
sorry, I forgot to change selector for number type field, it should go like this:
var phones = $('#df_field_<your_field_key> .value');
Dear Rudi and Viktor,
Thank you both for your recommendations. So I combined two of your solutions and managed to make it works for number type field "beru_phone." But not what I was looking for. This is the code I had tried in listing_details.tpl page
User input in beru_phone and it show on detail page 123456789012. With code above it show *********012, but click on it it still show 123456789012.Quote:
<script type="text/javascript">
{literal}
$(document).ready(function(){
var phones = $('#df_field_beru_phone .value');
$(phones).each(function(){
var unformatted = $(this).text();
$(this).text(unformatted.replace(/(.)(?=(\d{4})+$)/g,'$1-'));
var phone = $(this);
var default_value = phone.text();
var chars_to_mask = default_value.length - 4;
var mask_phone = Array(chars_to_mask + 1).join("*") + default_value.substring(chars_to_mask);
phone.text(mask_phone).removeAttr('href').toggleCl ass('mask');
phone.css('cursor', 'pointer');
$(phone).filter('.mask').click(function(){
$(this).text(default_value);
$(this).attr('href', 'tel:' + default_value).toggleClass('mask');
});
});
});
{/literal}
</script>
I'm looking to make it show as 1234-5678-9012. Also it doesn't need masked since this is public phone number on yellow page.
So I tried to remove masked featured and hope it will change 123456789012 to 1234-5678-9012 with this code
But nothing changed. :((((Quote:
<script type="text/javascript">
{literal}
$(document).ready(function(){
var phones = $('#df_field_beru_phone .value');
$(phones).each(function(){
var unformatted = $(this).text();
$(this).text(unformatted.replace(/(.)(?=(\d{4})+$)/g,'$1-'));
var phone = $(this);
var default_value = phone.text();
});
});
{/literal}
</script>
On listing detail page still show 123456789012
Hu hu hu (T_T)
Actually, I provided necessary code below, check carefully, see my 3d post from the top
Yes Rudi, I read your reply yesterday when you provided this code below:
I guess the red part is what change 123456789012 to 1234-5678-9012? I added it in my last try, it doesn't change anythingQuote:
$(document).ready(function(){
var phones = $('div[id*="your_field_key"] .value a');
$(phones).each(function(){
var unformatted = $(this).text();
$(this).text(unformatted.replace(/(.)(?=(\d{4})+$)/g,'$1-'));
var phone = $(this);
var default_value = phone.text();
var chars_to_mask = default_value.length - 4;
var mask_phone = Array(chars_to_mask + 1).join("*") + default_value.substring(chars_to_mask);
phone.text(mask_phone).removeAttr('href').toggleCl ass('mask');
phone.css('cursor', 'pointer');
$(phone).filter('.mask').click(function(){
$(this).text(default_value);
$(this).attr('href', 'tel:' + default_value).toggleClass('mask');
});
});
});
Or did you mean your reply a few hours ago?
It only have the following correction
:(Quote:
sorry, I forgot to change selector for number type field, it should go like this:
var phones = $('#df_field_<your_field_key> .value');
I've corrected that post and now it should work properly, check it
The reason is that the field was surrounded by spaces and I've added a code which trims them
How is it when you have to create a new field? 'telephone' ?
How is it when you have to create a new field? 'telephone' ?