简体   繁体   English

如何在Rails的f.input上使用蒙版?

[英]How can I use masks on f.input on Rails?

First of all, sorry if I made language mistakes, this is not my mother tongue. 首先,对不起,如果我犯了语言错误,那不是我的母语。

I'm learning RoR and I'm building a CRUD to register the information of a lot of computers, and I'm using Simple Form to generate the forms. 我正在学习RoR,并且正在构建CRUD以注册许多计算机的信息,并且正在使用“简单表单”来生成表单。 My question is, how can I use masks in the f.input element? 我的问题是,如何在f.input元素中使用蒙版?

Like when the user goes to insert the Ip adress, he get something like ---.---.---.--- in the text field. 就像用户去插入IP地址一样,他在文本字段中得到---.---..--..--。

if helps, here is this part of the form: 如果有帮助,这是表格的这一部分:

<div class="field">
    <%= f.input :mac_adress, label: 'Type the machine\'s MAC ADRESS: ', placeholder: 'XX:XX:XX:XX:XX:XX' %>
</div>
<div class="field"> 
    <%= f.input :patrimony, label: 'What is the patrimony number? ', placeholder: 'XXXXXX' %>
</div>
<div class="field"> 
    <%= f.input :ip, label: 'Inform the IP adress: ', placeholder: 'XXX.XXX.XXX.XXX' %>
</div>
<div class="field"> 
    <%= f.label :lab_id %>: 
    <%= f.text_field :lab_id, :value => @machine.lab.name, :hidden => true %>
</div>
<div class="actions">
    <%= f.button :submit %>
</div>

Thanks for any help, and if any additional information needed just ask. 感谢您的帮助,如果需要任何其他信息,请询问。

Mine: 矿:

<%= f.text_field :phone, class: "form-control", :required => true, :data => {:mask=> '999-999-9999'} %>

Yours: 你:

<%= f.input :ip, label: 'Inform the IP adress: ', placeholder: 'XXX.XXX.XXX.XXX', :data=> {:mask=> '999.999.999.9999' %>

add this js in your application.js 在您的application.js中添加此js

jasny/jasny-bootstrap.min.js jasny / jasny-bootstrap.min.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM