Giter VIP home page Giter VIP logo

jquery.validate.bootstrap.popover's Introduction

jquery.validate.bootstrap.popover

Show error message via bootstrap popover for jquery validate.

Instead of calling $('#form_id').validate(), call this:

$(function() {
	$('#form_id').validate_popover();
});

Check live demo here and here.

Dependency

Options

The plugin accepts options as a single object argument. Pass in the options like this:

$('#form_id').validate_popover({ popoverPosition: 'top' });

Supported options are:

  • popoverPosition Supported values: 'right', 'top'; default to 'right'

  • popoverContainer The container popover message will append to, default: 'body'

  • hideForInvisible The flag to control if popover should be hidden for invisible validated element, default: true

  • beforeShowError A function will be called before the error popover shows, this of the function is the input html element validated:

      $('#form_id').validate_popover({ beforeShowError: function(message) { 
          alert(this.name + ": " + message); 
        }
      });
    
  • get_offset_element A function will be called when positioning error popover relative to the returned element, default implmentation is returnning the validated element. e.g. Issue 6:

      $('#form_id').validate_popover({ get_offset_element: function(element) {
          if ($(element).attr("id") == "test") {
              return $(element).siblings('.bootstrap-select');
          } else {
              return $(element);
          }
        }
      });
    

HTML data attribute options

  • data-popover-position Supported values: 'right', 'top', this will override the global setting passed to validate_popover calling.

      data-popover-position = "top"
    
  • data-popover-offset Adjust the offset of the popover message, format is "top,left", like the following example will decrease the top by 10, and increase the left by 100:

      data-popover-offset = "-10,100"
    
  • data-popover-hide-for-invisible Set to false to allow error popover is displayed even for invisible validated element:

      data-popover-hide-for-invisible="false"
    

Public Methods

Public methods could be called:

$.validator.reposition(); // re-position all popovers

Public methods list:

  • hide_validate_popover Hide the popover for a validated element:

      $.validator.hide_validate_popover($("#client_email"));
    
  • show_error Display error message programatically for an element:

      $.validator.show_error("You need to choose a template from the list.", $("#template"));
    
  • reposition Re-position all popovers when no argument is given; otherwise, only re-position popovers for given validated elements. Useful to put into window resize handler. e.g.

      $.validator.reposition($("#client_email, #client_password"));
    

License

jquery.validate.bootstrap.popover is licensed under the MIT license.

jquery.validate.bootstrap.popover's People

Contributors

asgaroth avatar mingliangfeng avatar mrdnote 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery.validate.bootstrap.popover's Issues

Possible bug with select elements

When a select element is required, a validate-popover node is created for each one of the select's options. Thats because of the following statement:
hide_validate_popover: function(element) {
var ele, _i, _len, _results;
if (element.length > 1) {..

Where element is not the jquery object, but the actual html node.

Usage question

I have a bootstrap modal in which I am trying to do this and it is not working.

The dialog is rendered AFTER an ajax call spits outs the HTML and appends it to the DOM. It has a button whch should kick of validations. Hence the delegate.

$("body").delegate('#somebutton"','click',function(){

    $('#formid').validate_popover({onsubmit: false,popoverPosition: 'top'});

    if(!$("#input1").val()) {
        $.validator.show_error("You need to choose a template from the list.", $("#input1"));
        return false;
    }
          ....

Nothing happens with this code. Is it not supossed to work with modals.

When use Bootstrap’s Dropdown boxes (SELECT OPTION), it puts an small empty popover on validated dropdown boxes.

I’m using your jquery.validate.bootstrap.popover but have one small problem.
When I use Bootstrap’s Dropdown boxes (SELECT OPTION) your plugin puts an small empty popover on validated dropdown boxes.
I believe the reason is that a dropdown box is not a “single part” but an “multipart” component.
I believe your plug-in doesn’t handle multipart inputs correctly.
Do you have any advice?

"popoverContainer" doesn't work

$("#myform").validate_popover({popoverContainer:"#mycontainer"});

Is that wrong? The pop still append to the body. By the way, how can I set the default popoverContainer? I don't want to set it so many times.

Thank you!

No popovers when using empty option values in a select

In my application every dropdown has an <option value=””>Make a choice</option>.
This is semantically correct in HTML 5 and common practice.

The jQuery Validation Plugin has no problems identifying those as INVALID when you put the rule “required: true”.

This plugin also marks the empty option as INVALID (hence the red class) but doesn’t show the PopOver.

Please check. Thanks.

popover inside modal

I have another problem when validating inside a modal dialog. The popover doesn't seem to be positioned properly next to the element if the background of the dialog (the body of the page) is scrolled.

If fixed this by adding the following code to reset_position():

  var modal_content = $(element).closest('.modal-content');
  if (modal_content.length) {
    top_adjust -= modal_content.offset().top - 20;
  }

Could you tell if it would be ok to add this to the source or would you rather add a new callback, e.g. get_offset_position that one would pass as a parameter in validate_popover()?

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.