Code Monkey home page Code Monkey logo

bootstrap-validate's Introduction

bootstrap-validate

GitHub Workflow Status Lint GitHub Workflow Status Lint GitHub release (latest SemVer) npm GitHub

A simple Form Validation Utility for Bootstrap 3, Bootstrap 4 for Humans.

Demo

Supported Versions

bootstrap-validate Version Bootstrap Version Documentation
v1 Bootstrap 3 v1 Download + Docs
v2 Bootstrap 4 v2 Download + Docs

Documentation

Read the Documentation at bootstrap-validate.js.org.

Quick Start

$ npm i bootstrap-validate

Include the bootstrap-validate.js script:

<script defer="defer" src="bootstrap-validate.js"></script>

We want the #name to be not longer than 30 characters!

<div class="form-group">
    <label class="control-label">Enter a Name</label>
    <input id="name">
</div>

<script>
bootstrapValidate('#name', 'max:30:Your name must not be longer than 30 characters');
</script>

Validating an #email address couldn't be easier!

<div class="form-group">
  <label for="email" class="control-label">Enter your E-Mail</label>
  <input class="input" id="email">
</div>

<script>
bootstrapValidate('#email', 'email:Enter a valid email address');
</script>

More Features!

See the v2 Documentation on https://bootstrap-validate.js.org/v2/ to see all available validation features, examples, and usage with module bundlers.

Examples

See examples/ for real-world usage.

Download

You can find current Releases under Releases and older Releases for Bootstrap 3 and Bootstrap 4 in the Download Archive.

Changelog

See CHANGELOG.

Tests

Validation Rules are at least unit-tested. Use npm test to spin up the test suites.

License

Licensed under the MIT License, see LICENSE.

bootstrap-validate's People

Contributors

pascalebeier avatar pkeg avatar renovate-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bootstrap-validate's Issues

After validate ajax form post

Hi,
I'm happy to give you an example of how to post as ajax after the checks are done.

My Ajax form post example:

 $(document).ready(function(){
        $(".UrunSorgula").click(function(){
            var data = $("#UrunSorgula").serialize();
            $.ajax({
                type  : "POST",
                url   : "ajax/urun_sorgula.php?page=UrunSorgula",
                data  : data,
                success : function(cevap)
                {
               $(".UrunSorgulaSonuc").html(cevap);
               //document.forms["UrunSorgula"].submit(); //first submit
                document.forms["UrunSorgula"].reset(); //and then reset the form values
                }    
              });
            return false;
        });
    });

Thank you

Is it possible to add an Ajax check before submitting the form?

Hi there,
In addition to client-side validation (which you did nicely), I want to add another step to validate the input on the server. As an example, suppose I wanna check for an email as username.
The first step would be checking the email format (browser side), and if the email format was correct, I wanna send the field value to the server (without pressing on submit button - it should be done as the next step of validation), to make sure this email was not taken before.
Can you tell me how to implement this feature?

Emit Events

Every bootstrapValidate() method call should be emitting events for invalidity and validity.

Validation runs before submit

It is better to be as Validating after clicked the submit button.
Because for an example,
In email validation, the validation message comes when I started to typing. It's feels not good while typing first.
May be the user going to do the thing calmly, then the Red colored messages comes in he maybe feels scared.

My request is, the function should work after click the submit.
I manually tried many times, since I started web development recently it's bit hard to do.

[DISCUSSION] Version 3 Concepts

I'm currently in the process of undertaking a complete refactor of this library to solve some problems:

Problems to be solved

  • Usage is ... ugly. I dislike it how you assemble a super big string with rules and options
  • Maintaining two different versions for Bootstrap 3 and 4 sucks.

Features

  • The user should be able to use any Bootstrap Version and to switch between these
  • The user should be able to customize the error output

Ideas

The new API could look like this:

BootstrapValidate.usePreset(BootstrapValidate.Presets.Bootstrap4)

const myPreset = {};

BootstrapValidate.usePreset(myPreset);

Users should be able to set the Preset per Input / Form as well.

However I'm not entirely certain of how the user sets the rules. A more form oriented approach would be cool, where the user maps fields to rules, somewhat like:

new BootstrapValidate('#myForm', {
  fields: [
    '#email': {
      rules: [
        BootstrapValidate.Email('Enter a valid email address'),
        BootstrapValidate.Min(20, 'Enter at least 20 Characters')
      ]   
   }
  ]
}

I appreciate any input!

How to check validation?

How can I check if the validation is true?

Only adding

bootstrapValidate('.form-control.email', 'required|email:Enter a valid E-Mail!');

Is not enough. I need something like (I have to prevent the default form submit or check before an ajax request):

if (bootstrapValidate.allValidationsAreTrue()) {
...
}

What is release 1.1.0?

The GitHub release page show a version 1.1.0 published on Mar 29, 2018 but this version does not appear in changelog neither as default download link for v1.

What is this release?

Adding the .has-error class does not work for complex forms

For example:

<div class="form-group">
    <label class="control-label col-sm-2">Label</label>
    <div class="col-sm-10">
         <input class="form-control">
     </div>
</div>

In that case, the error class is added to the direct parent of the input, which would be div.col-sm-10.

NPM module updated?

I notice when pulling in bootstrap-validate using yarn add bootstrap-validate I get version 2.1.3 but as per documentation, latest version seems to be: 2.2.0

  <script src="https://cdn.rawgit.com/PascaleBeier/bootstrap-validate/v2.2.0/dist/bootstrap-validate.js" ></script>

Form submits with errors

Currently, the form submits even when there are errors present. Is there a way to check for errors before submitting the form?

display error message

Hi, is there any way to display error message when the focus for the current input is lost ?
thanks for your works ;-)

matches rule returns "o.default[e[0]] is undefined"

The "matches" rule returns an undefined error.
bootstrap-validate 1.0.11, bootstrap 3.3.7

html
<div class="form-group">
<label for="inputMatch1" class="control-label col-sm-2">type some stuff</label>
<div class="col-sm-10">
<input id="inputMatch1" type="text" class="form-control">
</div>
<label for="inputMatch2" class="control-label col-sm-2">type the same stuff</label>
<div class="col-sm-10">
<input id="inputMatch2" type="text" class="form-control">
</div>
</div>

javascript
bootstrapValidate( '#inputMatch2', 'matches:#inputMatch1:type the text from the callback test' );

Return form submitting when input field is not valid

Hi, I used this:
bootstrapValidate( '#docs-demo', 'email:Enter a valid E-Mail Address!' );
bootstrapValidate( '#docs-demo', 'required:Please fill out this field!' );
And it works, It will display invalid messages
But return form submitting too,
how i can fix it ?
thanks

integer match

I noticed that parseFloat is used for validation.
This means that 00aa is considered a valid integer which obviously is not.

Stef

Error Handling

We should notify users if they provide falsy arguments via console.warn.

Removing a rule?

Is there anyway to remove a rule once added? In cases where you have some conditional requirements for a rule. I.E. This input is only required if X input is filled in and Y input equals such and such type of thing.

Finalize Docs

  • Get some time on writing the docs :)
  • Add Info for ES6 Environments
  • Add Info on how to Contribute
  • Add Code snippets
  • Add more usage examples; ideally of every rule and real world examples

Rule Wishlist

  • before(date, dateFormat)
  • after (date, dateFormat)
  • date(format)
  • regexp(regexp)
  • phone (format)
  • file(extension)
  • divisible (#9 (comment))
  • url
    URL Validation
  • matches
    Two fields that should match, e.q. for password confirmations. The v1 API makes that super fuzzy.
  • endswith(string)
    Ensure a given string ends with a given string
  • startswith(string)
    Same as above but starting with
  • contains(string)

How difficult would be to add a Numeric Range option?

Hi there,

I have a form I'm working on which requires a numeric range so I think currently the regex option is probably the only route for me to go but I feel like the website may need some more examples since the regex I have doesn't seem to be working as expected.

So I was hoping maybe to make the overall process easier, if there was a new numeric range option where users could provide both min and max values (and enable floating point or just require integers) that would meet my needs currently.

Another quick note is that if I have a field set to be required, but that message does not appear if I load the page and quickly hit submit...it only appears when I type something in and then use backspace and erase everything.

Thank you for your work on this :-)!

Equal rule

I would like a rule to compare two fields that the value is equal, passing parameters by the id of the two fields. Thanks.

Error Icons

I'd like the user to be able to choose an error icon per input.
Also, he needs to be able to set choose a custom icon provider, e.g. font-awesome.

For the initial Release of 1.1.0, bootstrap icons and font-awesome would be sufficient.

The API might look like this:

<script>
// Default Bootstrap Icon
bootstrapValidate(document.getElementById('email'), 'email', { icon: true });
// Another Bootstrap Icon
bootstrapValidate(document.getElementById('email'), 'email', { icon: 'glyphicon glyphicon-asterisk'});
// Font Awesome Icon
bootstrapValidate(document.getElementById('email'), 'email', { icon: 'fa-error', provider: 'font-awesome' });
</script>

This way, one had to programmatically maintain different icon providers.

object does not support object 'closest'

I am using bootstrap 4.1 and I have an issue with your first example that you put on website..When I start to type some invalid text in email field I am getting an erorr in my visual studio - object does not support object 'closest'

empty input & RegExp based rules

When using a RegExp based input (tested with alphanum and ISO8601) an empty input is not allowed if something was filled in.

So when you fill in the field with wrong input, the invalid state is triggered.
But when you clear the input, the invalid state is not removed.

Stef

Callback function

bootstrapValidate('#myInput', 'rule', function (isValid) {
if (isValid) {
alert('Element is valid');
} else {
alert('Element is invalid');
}
});

Callback function doesn't execute

Call validation on click

Missing a method to trigger validation by clicking on a button, ie:

function checkFormSubmit(){
bootstrapValidate('#tbEmail').validate();
}

Change to 'is-valid' class

Hello,
after validation it would be perfect to change the input class from: is-invalid to is-valid.
This would stylize the input border color from red to green. At the moment it just removes the is-invalid, which utter in a red border-color changing to default input border.
Thanks, malmr

Refactor errors.js

Currently all the DOM Manipulations happen in error.js which is really fuzzy.

Should be changed into ElementModification.js or something to simplify validation for elements other than input in the future.

Triggering errors on form submit?!

Hello,
first of all thanks a lot for this library, it has been a lot of help .. but i'm having this issue where i want to trigger input errors on submit and prevent submitting?
I tried calling bootstrapValidate inside $('#myForm').submit(function (event){} but it seemed that it's not triggering the errors only making the function start the validations!
Anything that I'm missing ?

best regards !

Support Bootstrap 4

Since the first Bootstrap 4 Beta shipped bootstrap-validate should support the latest branch.

Regex Issue when using :

I am using the following regex

bootstrapValidate('#inputfield', 'regex:/^(my:track:[a-zA-Z0-9]{22}$)/:Invalid')

The issue is I am using : inside the regex match which conflicts with the separator options.

How can I stop the : regex conflicting? Thanks!

Usage with Angular

How should I call the bootstrapValidate function in Angular CLI ? Angular will not allow the calling of script tags inside the template of component.

Multiple rules of the same type

Putting in multiple rules of the same type leads to only the last one being evaluated.

Example for replication:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<body>

<div class="form-group">
        <label class="control-label">Enter a Name</label>
        <input id="name" />
</div>
<script src="assets/bootstrap-validate/dist/bootstrap-validate.js"></script>
<script>
        bootstrapValidate('#name', 'regex:[a-z]:Must have lowercase|regex:[A-Z]:must have uppercase');
    </script>
</body>

match rule doesn't update if matches: field is changed instead of input field

How to replicate the problem:
2 Fields: LogonID1, LogonID2
Code:
bootstrapValidate('#LogonID2', 'matches:#LogonID1: Logon IDs do not match.');

User will input a username in LogonID1 field incorrectly 'user123', then input correct username 'user1234' into LogonID2. User will then update LogonID1 field to 'user1234' and the error message will not go away.

Regex File Type

Doesn't work
Rule I apply : "regex:(xlsx|png)+$:Please upload xlsx file !"
Uncaught TypeError: Cannot read property 'apply' of undefined

This work
Rule I apply : "regex:(xlsx)+$:Please upload xlsx file !"

Any solution ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.