PHP Classes

File: public/asset/vendor/jquery-validation/src/additional/require_from_group.js

Recommend this page to a friend!
  Classes of fathurrahman   mnTemplate   public/asset/vendor/jquery-validation/src/additional/require_from_group.js   Download  
File: public/asset/vendor/jquery-validation/src/additional/require_from_group.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: mnTemplate
Route HTTP requests to callback functions
Author: By
Last change:
Date: 1 year ago
Size: 1,451 bytes
 

Contents

Class file image Download
/* * Lets you say "at least X inputs that match selector Y must be filled." * * The end result is that neither of these inputs: * * <input class="productinfo" name="partnumber"> * <input class="productinfo" name="description"> * * ...will validate unless at least one of them is filled. * * partnumber: {require_from_group: [1,".productinfo"]}, * description: {require_from_group: [1,".productinfo"]} * * options[0]: number of fields that must be filled in the group * options[1]: CSS selector that defines the group of conditionally required fields */ $.validator.addMethod( "require_from_group", function( value, element, options ) { var $fields = $( options[ 1 ], element.form ), $fieldsFirst = $fields.eq( 0 ), validator = $fieldsFirst.data( "valid_req_grp" ) ? $fieldsFirst.data( "valid_req_grp" ) : $.extend( {}, this ), isValid = $fields.filter( function() { return validator.elementValue( this ); } ).length >= options[ 0 ]; // Store the cloned validator for future validation $fieldsFirst.data( "valid_req_grp", validator ); // If element isn't being validated, run each require_from_group field's validation rules if ( !$( element ).data( "being_validated" ) ) { $fields.data( "being_validated", true ); $fields.each( function() { validator.element( this ); } ); $fields.data( "being_validated", false ); } return isValid; }, $.validator.format( "Please fill at least {0} of these fields." ) );