Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the default message of the required field in the popover of form-control in bootstrap?

 <form class="form-asd" role="form">     <h2 class="form-signin-heading">login</h2><hr />     <label class="control-label"  for="username">Username</label>     <input class="form-control" type="email"  required="" placeholder="username"data-error="enter username"></input>     <label class="control-label"  for="username">password</label>     <input class="form-control" type="password"  required=" " placeholder="Password"></input>     <label class="checkbox"></label>     <button class="btn btn-lg btn-primary " type="submit">submit</button> </form> 

how can we change this default message of popover of the require field "Please fill out this field "to "please enter username"

like image 723
dpndra Avatar asked Jun 24 '14 15:06

dpndra


People also ask

Which is the default form in bootstrap?

Vertical form (this is default)

Which classes does Bootstrap provides in order to be used only when the form control is invalid?

Here's how form validation works with Bootstrap: HTML form validation is applied via CSS's two pseudo-classes, :invalid and :valid . It applies to <input> , <select> , and <textarea> elements. Bootstrap scopes the :invalid and :valid styles to parent .


1 Answers

You can use setCustomValidity function when oninvalid event occurs.

Like below:-

<input class="form-control" type="email" required=""      placeholder="username" oninvalid="this.setCustomValidity('Please Enter valid email')"> </input> 

Update:-

To clear the message once you start entering use oninput="setCustomValidity('') attribute to clear the message.

<input class="form-control" type="email"  required="" placeholder="username"  oninvalid="this.setCustomValidity('Please Enter valid email')"  oninput="setCustomValidity('')"></input> 
like image 131
Mritunjay Avatar answered Oct 13 '22 06:10

Mritunjay