创建表单时如何添加必填字段? [英] How can i add required field while creating a form?

查看:170
本文介绍了创建表单时如何添加必填字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

  <div class="form-group">
    <div class="col-md-4">
      <label class="control-label">Mobile Number:</label>
    </div>
    <div class="col-md-8">
      {!! Form::input('number', 'mobile',  null, ['type' => 'number', 'min' => 0, 'id' => 'mobile', 'class' => 'input-lg form-control TabOnEnter', 'placeholder' => 'Eg: 9876543210', 'tabindex' => 15]) !!}
    </div>
  </div>

在这里我想根据需要提供此手机号码字段,如何将其添加到我的代码中? 我在创建表单时有3个步骤,并且在步骤1中有移动电话号码,当我单击下一个按钮而不添加移动电话号码时,它应该显示一条警报消息.现在,它正在显示所需移动字段的警报消息,只有在第3步的最后一步(即)中单击提交"按钮之后.

Here i want to give this mobile number field as required, how can i add it in my code? And i am having 3 steps in the creation of form and i am having mobile number in step1, when i am clicking the next button without adding mobile number, it should display an alert message..Now it is displaying alert message of mobile field required, only after clicking submit button in last step (i.e) in step 3..

推荐答案

您需要使用jquery

  <div class="form-group">
    <div class="col-md-4">
      <label class="control-label">Mobile Number:</label>
    </div>
    <div class="col-md-8">
      {!! Form::input('number', 'mobile',  null, ['type' => 'number', 'min' => 0, 'id' => 'mobile', 'class' => 'input-lg form-control TabOnEnter', 'placeholder' => 'Eg: 9876543210', 'tabindex' => 15]) !!}

    <button style="margin-right:20px;" class="next_button btn btn-info active nextBtn btn-md pull-right" type="next" >Next</button>
    </div>
  </div>

$(document).ready(function(){
   $('.next_button').click(function(event){
        if ($('#mobile').val() == ""){
            event.preventDefault();
            alert('Enter the number');
        }
    });
});

在现有代码中添加了next_button

这篇关于创建表单时如何添加必填字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆