templates for fields

Archived from the Xataface Users forum.

shardison — Mon Nov 12, 2012 2:47 pm

Is there a way to create a template for a field that would automatically supply dashes or slashes when someone is editing or entering data.

For example for dates
/ /
or for social security numbers

    • so that as someone enters a date they only have to enter numbers and they would show up in the right place automatically. Or as someone enters a social security number the dashes will be supplied automatically

Thanks
Seth


Jean — Tue Nov 13, 2012 2:11 am

Why don’t you use 3 fields with a javascript to put the cursor in the right field ? Then you join them with a beforeSave trigger in a calculated field.
Jean


shannah — Tue Nov 13, 2012 9:06 am

You could either do this with javascript by attaching a change handler to the field; or you could do this with a beforeSave() trigger in PHP to modify it before it is saved. The way I usually do it is to remove all formatting for the saved version (if I care about format at all), using the beforeSave() trigger, then I format it the way I want with the fieldname__display() delegate method.

-Steve


shardison — Sat Nov 24, 2012 11:55 am

Steve,
I agree that I can run a javascript to handle the input mask. I was wondering if jquery is loaded by default with xataface or do I have to explicitly call it and the javascript I have for the input mask that relies on jquery?


shardison — Sun Nov 25, 2012 7:58 am

I found that jquery does load by default. I found a cool javascript called maskedinput.js at http://digitalbush.com/projects/masked-input-plugin/ that has the ability to create many types of input mask. The script was created by Josh Bush. I don’t want to take any credit for the solution. The internet is an awesome bedrock for collaborative work. Just want to give a shout out to all the people like Steve who advance software development