⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Input Mask



Copper
  • profile picture
  • Member

Posted 19 February 2013 - 17:27 PM

Hello,

 

Are input mask possible and if so how? To be more specific phone and currency masks, such as (xxx)xxx-xxxx. I am new to Codeigniter and Grocerycrud so specific examples would be very helpful.

 

Thanks for taking the time to read this.


victor
  • profile picture
  • Member

Posted 19 February 2013 - 19:05 PM

you can use javascript for that and validate it on the server too

victor
  • profile picture
  • Member

Posted 19 February 2013 - 19:05 PM

Welcome to the forum )

Copper
  • profile picture
  • Member

Posted 19 February 2013 - 19:28 PM

Victor thanks. I'm sorry if my questions are at the beginner level. I have a few years of php experience and a little javascript experience. I'm trying to learn oop, codeigniter and grocerycrud.

 

Where should I put the javascript and how should I call it?

 

Thanks!


victor
  • profile picture
  • Member

Posted 19 February 2013 - 19:31 PM

do you want to validate it or you need to make a hint in the input ? for example (___) __________

Copper
  • profile picture
  • Member

Posted 19 February 2013 - 19:37 PM

On the input.


victor
  • profile picture
  • Member

Posted 19 February 2013 - 20:06 PM

There are javascript libraries to make it. I have seen it before, but I dont know where

Copper
  • profile picture
  • Member

Posted 19 February 2013 - 20:25 PM

Here is a site that offers the javascript code with a demo.

 

http://digitalbush.com/projects/masked-input-plugin/

 

I don't know where to install it in grocerycrud.


victor
  • profile picture
  • Member

Posted 19 February 2013 - 20:32 PM

First, include the jQuery and masked input javascript files. in to header your view file then write this (in header too) jQuery(function($){ $(".Your_input_id").mask("(999) 999-9999",{placeholder:"(___)) ___-____ "}); });

Copper
  • profile picture
  • Member

Posted 20 February 2013 - 01:17 AM

Making progress. I found Grocerycrud already loads jquery. I loaded the input mask javascript file after the jquery load. After changing your code slightly I was able get the mask to show up and could enter the phone number properly but it won't save what I typed in.

 

Here is what I changed your code to :    

 

    jQuery(function($){

        $("#field-phone").mask("(999)999-9999",{placeholder:"_"});

    });

 

If I used ".field-phone" instead of "#field-phone" the mask wouldn't show up.

 

Also if I used "(___)) ___-____ " as the place holder it kept repeating itself.

(___)) ___-____(___)) ___-____(___)) ___-____(___)) ___-____

 

Again thanks for your help.


Copper
  • profile picture
  • Member

Posted 20 February 2013 - 17:26 PM

It looks like I have it working now. I changed the field type from INT to varchar and the length from 10 to 13.

 

Thanks a lot for your help Victor.