Dude, one lil example:
put this in your public/javascript
function maskTelefone(source, event) {
return mask(source, event, '99 9999-9999', '0123456789');
}
then, in your view, call like this
<%= f.text_field :del_fone, :size => 13, :maxlength => 12, :onkeypress =>
"return maskTelefone(this,event);" %>
works fine fella!
any doubt, please, talk
2011/7/1 Walter Lee Davis <[email protected]>
> That's done with JavaScript. Have a google for the term 'input mask', and
> step well back when you see the zillions of results.
>
> Walter
>
>
> On Jul 1, 2011, at 9:48 AM, Rodrigo Ruiz wrote:
>
> How can I manage to make it appear automatically, the + and () and - in
>> the telephone +00(00)0000-0000 and the / in the date like mm/dd/yyyy, as the
>> user types only numbers? And how to enable only numbers to be typed?
>>
>> And what type are those kind of information saved in the database?
>> strings?
>>
>>
>> On Fri, Jul 1, 2011 at 3:29 PM, Walter Lee Davis <[email protected]>
>> wrote:
>>
>> On Jul 1, 2011, at 9:13 AM, Rodrigo Ruiz wrote:
>>
>> Can't I do that only with ruby and rails?
>>
>> On Fri, Jul 1, 2011 at 3:25 AM, Leoncio Caminha <
>> [email protected]> wrote:
>> make on javascript for that and call in :onkeypress => 'yourJS(this);' i
>> think so
>> Em 30/06/2011, às 22:23, Rodrigo Ruiz escreveu:
>>
>> You could certainly clean up any user input in a before_validation filter
>> method. I don't know how you would figure out which mask to use, but what I
>> usually do is first strip out anything that isn't a numeral, and then take
>> the numbers back through a mask so that first n numbers are area code, next
>> are exchange, then station, then extension if anything is left over. If you
>> had multiple nations or any optional elements (country code) then the
>> problem gets a lot harder to solve.
>>
>> By the way, as Leoncio pointed out, this could all be done in JavaScript,
>> and the implementation is largely the same; string operations being more or
>> less identical (and with Prototype.js, even having the same names for the
>> functions) in either JavaScript or Ruby.
>>
>> Walter
>>
>>
>> > Well, that's basically it, how can I make an input field for date like
>> mm/dd/yyyy and for telephone like +xx (xx) xxxx-xxxx.
>> >
>> > Thank you,
>> > Rodrigo
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups "Ruby on Rails: Talk" group.
>> > To post to this group, send email to rubyonrails-talk@googlegroups.**
>> com <[email protected]>.
>> > To unsubscribe from this group, send email to
>> rubyonrails-talk+unsubscribe@**googlegroups.com<rubyonrails-talk%[email protected]>
>> .
>> > For more options, visit this group at http://groups.google.com/**
>> group/rubyonrails-talk?hl=en<http://groups.google.com/group/rubyonrails-talk?hl=en>
>> .
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ruby on Rails: Talk" group.
>> To post to this group, send email to
>> rubyonrails-talk@googlegroups.**com<[email protected]>
>> .
>> To unsubscribe from this group, send email to
>> rubyonrails-talk+unsubscribe@**googlegroups.com<rubyonrails-talk%[email protected]>
>> .
>> For more options, visit this group at http://groups.google.com/**
>> group/rubyonrails-talk?hl=en<http://groups.google.com/group/rubyonrails-talk?hl=en>
>> .
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ruby on Rails: Talk" group.
>> To post to this group, send email to
>> rubyonrails-talk@googlegroups.**com<[email protected]>
>> .
>> To unsubscribe from this group, send email to
>> rubyonrails-talk+unsubscribe@**googlegroups.com<rubyonrails-talk%[email protected]>
>> .
>> For more options, visit this group at http://groups.google.com/**
>> group/rubyonrails-talk?hl=en<http://groups.google.com/group/rubyonrails-talk?hl=en>
>> .
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ruby on Rails: Talk" group.
>> To post to this group, send email to
>> rubyonrails-talk@googlegroups.**com<[email protected]>
>> .
>> To unsubscribe from this group, send email to
>> rubyonrails-talk+unsubscribe@**googlegroups.com<rubyonrails-talk%[email protected]>
>> .
>> For more options, visit this group at http://groups.google.com/**
>> group/rubyonrails-talk?hl=en<http://groups.google.com/group/rubyonrails-talk?hl=en>
>> .
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ruby on Rails: Talk" group.
>> To post to this group, send email to
>> rubyonrails-talk@googlegroups.**com<[email protected]>
>> .
>> To unsubscribe from this group, send email to
>> rubyonrails-talk+unsubscribe@**googlegroups.com<rubyonrails-talk%[email protected]>
>> .
>> For more options, visit this group at http://groups.google.com/**
>> group/rubyonrails-talk?hl=en<http://groups.google.com/group/rubyonrails-talk?hl=en>
>> .
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to
> rubyonrails-talk@googlegroups.**com<[email protected]>
> .
> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscribe@**googlegroups.com<rubyonrails-talk%[email protected]>
> .
> For more options, visit this group at http://groups.google.com/**
> group/rubyonrails-talk?hl=en<http://groups.google.com/group/rubyonrails-talk?hl=en>
> .
>
>
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.