Limit the Length of a Text Attribute

Permalink 1 user found helpful
I want to limit the length of a few text attributes. One of them is a phone number that I have named HomePhone and I want to limit it to 12 characters. It is editable by a logged in site user, and I want to have all of these data fields the same length. I want all of the phone numbers to be in the 123-456-7890 format and not (123)456-7890 so the data is easier to manage. How do I limit that and make it so when there are 12 characters in the text box they can't enter anything else?

I'm not a programmer, but I'm also not afraid to hack anything that I have instructions for what to do.

Thanks.

sogren
 
Mainio replied on at Permalink Reply
Mainio
Hi,

I think what you could do is a new attribute type for that purpose. So what you should do here is copy the text attribute and start with it.

Although you said you're afraid of doing this, here's how to do it:
1. Go to /site_root/concrete/models/attribute/types
2. Copy the ENTIRE FOLDER named "text"
3. Go to /site_root/models/
4. Create the same directory structure there so that you have /site_root/models/attribute/types
5. Copy the "text" folder there and rename it to "phone"
6. Open the controller and rename it to PhoneAttributeTypeController
7. Do the changes you need to do and install the attribute type from concrete

Here's some further guides on how to do customize the attributes:
Simple guide:
http://www.concrete5.org/documentation/how-tos/developers/custom-at...

HC guide:
http://www.concrete5.org/documentation/how-tos/developers/create-a-...


We can also do this for you if you're interested in paying for it. Just PM me for further details!


Antti / Mainio
jshannon replied on at Permalink Reply
jshannon
Hi. I just came across this post and thought I'd contribute for people who come by in the future.

I created an "advanced text" attribute for cases like this. Right now it only supports email addresses and web addresses, but things like length and phone number can be:

a) added to the source pretty with a few lines of code, without needing to recreate an entire attribute type, or
b) entered as a regular expression

Both of the above needs someone who's at least comfortable with code. The attribute is athttp://www.concrete5.org/marketplace/addons/lerteco-advanced-text-a... .

James