UNPKG

formvalidation

Version:

The best jQuery plugin to validate form fields. Support Bootstrap, Foundation, Pure, SemanticUI, UIKit and custom frameworks

51 lines (46 loc) 1.67 kB
/** * notEmpty validator * * @link http://formvalidation.io/validators/notEmpty/ * @author https://twitter.com/nghuuphuoc * @copyright (c) 2013 - 2015 Nguyen Huu Phuoc * @license http://formvalidation.io/license/ */ (function($) { FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, { 'en_US': { notEmpty: { 'default': 'Please enter a value' } } }); FormValidation.Validator.notEmpty = { enableByHtml5: function($field) { var required = $field.attr('required') + ''; return ('required' === required || 'true' === required); }, /** * Check if input value is empty or not * * @param {FormValidation.Base} validator The validator plugin instance * @param {jQuery} $field Field element * @param {Object} options * @returns {Boolean} */ validate: function(validator, $field, options) { var type = $field.attr('type'); if ('radio' === type || 'checkbox' === type) { var ns = validator.getNamespace(); return validator .getFieldElements($field.attr('data-' + ns + '-field')) .filter(':checked') .length > 0; } if ('number' === type && $field.get(0).validity && $field.get(0).validity.badInput === true) { return true; } var value = validator.getFieldValue($field, 'notEmpty'); return $.trim(value) !== ''; } }; }(jQuery));