66 lines
1.9 KiB
JavaScript
Executable File
66 lines
1.9 KiB
JavaScript
Executable File
/**
|
|
* 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(root, factory) {
|
|
|
|
"use strict";
|
|
|
|
// AMD module is defined
|
|
if (typeof define === "function" && define.amd) {
|
|
define("validator/notEmpty", ["jquery", "base"], factory);
|
|
} else {
|
|
// planted over the root!
|
|
factory(root.jQuery, root.FormValidation);
|
|
}
|
|
|
|
}(this, function ($, FormValidation) {
|
|
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;
|
|
}
|
|
|
|
return $.trim($field.val()) !== '';
|
|
}
|
|
};
|
|
|
|
|
|
return FormValidation.Validator.notEmpty;
|
|
}));
|