Skip Navigation

[Resolved] apply mask custom fields

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 8 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 7 replies, has 2 voices.

Last updated by Luo Yang 8 years, 2 months ago.

Assisted by: Luo Yang.

Author
Posts
#439068

I am trying to: apply mask custom fields

first insert the function in my theme for js maskedinput as code

[php]function mascara_cadastro(){

is_singular('cpt')
wp_enqueue_script('masked-input', 'hidden link'.'/js/jquery.maskedinput.min.js', array('jquery'));

}
add_action('wp_enqueue_scripts', 'mascara_cadastro');</ code>

Note that I used is_singular to determine the created cpt

after entering the function to activate the mask in the custom field tool set "WPCF-field" as code

[php]function activate_masked_input(){
is_singular('cpt') ){
?>

<script type="text/javascript">

jQuery( function($){

$("#wpcf-field").mask("99/99/9999");

});

</script>

<?php
}
}
add_action('wp_footer', 'activate_masked_input');</ code>

and the function does not work, as much googled to find a solution and nothing could please help me

tks

#439226

Dear marcelo,

There is an error in your PHP codes, I suggest you modify it from:

function mascara_cadastro(){

is_singular('cpt')
wp_enqueue_script('masked-input', '<em><u>hidden link</u></em>'.'/js/jquery.maskedinput.min.js', array('jquery'));

}
add_action('wp_enqueue_scripts', 'mascara_cadastro');

To:

function mascara_cadastro(){
	if(is_singular('cpt')){
		wp_enqueue_script('masked-input', '<em><u>hidden link</u></em>'.'/js/jquery.maskedinput.min.js', array('jquery'));
	}
}
add_action('wp_enqueue_scripts', 'mascara_cadastro');

More help:
hidden link

#439477

the changes made and was as follows:

function mascara_cadastro(){
             
      if(is_singular('imovel')){
      wp_enqueue_script('masked-input', '<em><u>hidden link</u></em>'.'/js/jquery.maskedinput.min.js', array('jquery'));
  
    }
}
add_action('wp_enqueue_scripts', 'mascara_cadastro');

function activate_masked_input(){
      if(is_singular('imovel') ){
?>
 
         <script type="text/javascript">
 
                jQuery( function($){
                      
                     $("wpcf-preco-de-venda-ou-locacao").mask("999.999");
                    
                });
 
         </script>
 
<?php 
   }
}
add_action('wp_footer', 'activate_masked_input');

but still does not work, I'm trying to get the mask appear when you insert a new post on the backend, /wp-admin/post-new.php?post_type=cpt, is it necessary to make any other statement?

#439837

It is in wordpress admin side, I suggest you try with the wordpress action hook "admin_enqueue_scripts", for example,
1) create a JS file "masked_input.js" in same folder as file jquery.maskedinput.min.js, with below codes:

jQuery(document).ready(function($){
    $('input[data-wpt-id="wpcf-preco-de-venda-ou-locacao"]').mask("999.999");
});

2) modify the PHP codes as below:

function mascara_cadastro(){
	$current_screen = get_current_screen();
	if( isset($current_screen->post_type) && $current_screen->post_type == 'some-cpt'){
		wp_enqueue_script('masked-input', '<em><u>hidden link</u></em>'.'/js/jquery.maskedinput.min.js', array('jquery'));
		wp_enqueue_script('masked_input-js', '<em><u>hidden link</u></em>'.'/js/masked_input.js', array('jquery'));
	}
}
add_action('admin_enqueue_scripts', 'mascara_cadastro');
#440481

Perfect

I am very grateful to you Luo Yang

one more question, if I want to apply in more than one cpt I use array ( 'CPT1', 'CPT2', 'cpt3')?

#440616

Yes, you can modify the PHP codes as below:

function mascara_cadastro(){
    $current_screen = get_current_screen();
    if( isset($current_screen->post_type) 
		&& in_array($current_screen->post_type, array('some-cpt', 'some-cpt2', 'some-cpt3')){
        wp_enqueue_script('masked-input', '<em><u>hidden link</u></em>'.'/js/jquery.maskedinput.min.js', array('jquery'));
        wp_enqueue_script('masked_input-js', '<em><u>hidden link</u></em>'.'/js/masked_input.js', array('jquery'));
    }
}
add_action('admin_enqueue_scripts', 'mascara_cadastro');

please replace 'some-cpt', 'some-cpt2', 'some-cpt3' with the custom post type slugs.

More help:
hidden link

#440948

Luo I thank you very much. Sorry to extend the question, all you gave me so far worked perfectly.

My only problem is that the masks are being recorded in the database, which believe not ideal due to the use of data in research, filters, sort order, etc.

I questioned the developer jquery script about it, he informed me that the plugin is not responsible for recording the data with mask in the database.

You would have some light on this issue?

Thank you again.

#441136

Since the original problem has been resolved, please create another thread for the new question. this will help other users to find the answers.

And you will need describe more details for the questions:
What are the masks being recorded in the database? what do you want the value to be?
How do you setup the custom field? is it a custom single line field?

we need details to duplicate same problem, thanks

The forum ‘Types Community Support’ is closed to new topics and replies.