bootstrap form helper phone wont work

爱⌒轻易说出口 提交于 2019-12-11 14:16:47

问题


I m trying to make a website using form Bootstrap framework. As part of my code I have

<div class="control-group">
<label class="control-label" for="inputTell">Telephone</label>
<div class="controls">
<input type="text" id="inputTell" class="bfh-phone" data-format="(ddd) ddd-dddd">
</div>
</div>

This is the image:

It shouldnt be like that. It shouldn't accept any strings and it should give me the phone format like this:

I already have the necessary JS files in my directory but I am not sure why it is not working.


回答1:


Make sure the input field is inside a form. The phone helper will not work correctly otherwise.

<form>
  <div class="control-group">
    <label class="control-label" for="inputTell">Telephone</label>
    <div class="controls">
      <input type="text" id="inputTell" class="bfh-phone" data-format="(ddd) ddd-dddd">
    </div>
  </div>
</form>

Example jsfiddle




回答2:


also, the input type must be "text" or "tel" for formhelpers to work:

snippet part from bootstrap-formhelpers.min.js:

    ... ('form input[type="text"].bfh-phone, 
          form input[type="tel"].bfh-phone, span.bfh-phone').each(function(){
     ... 
 }); 

may be useful for someone




回答3:


you've forgotten to add <form> tag.

just put your code inside a <form> tag, and it will start working.

<form>

    <input type="text" id="inputTell" class="bfh-phone" data-format="(ddd) ddd-dddd">

</form>

Note: also add necessary classes of bootstrap like controls, form etc.




回答4:


I've try use type tel and another class

<div class="control-group">
   <input type="tel" class="form-control bfh-phone" data-format="(ddd) ddd-dddd" name="number" required>
</div>


来源:https://stackoverflow.com/questions/16750053/bootstrap-form-helper-phone-wont-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!