| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- (function($) {
- $.fn.bootstrapValidator.i18n.greaterThan = $.extend($.fn.bootstrapValidator.i18n.greaterThan || {}, {
- 'default': 'Please enter a value greater than or equal to %s',
- notInclusive: 'Please enter a value greater than %s'
- });
- $.fn.bootstrapValidator.validators.greaterThan = {
- html5Attributes: {
- message: 'message',
- value: 'value',
- inclusive: 'inclusive'
- },
- enableByHtml5: function($field) {
- var type = $field.attr('type'),
- min = $field.attr('min');
- if (min && type !== 'date') {
- return {
- value: min
- };
- }
- return false;
- },
- /**
- * Return true if the input value is greater than or equals to given number
- *
- * @param {BootstrapValidator} validator Validate plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options Can consist of the following keys:
- * - value: Define the number to compare with. It can be
- * - A number
- * - Name of field which its value defines the number
- * - Name of callback function that returns the number
- * - A callback function that returns the number
- *
- * - inclusive [optional]: Can be true or false. Default is true
- * - message: The invalid message
- * @returns {Boolean|Object}
- */
- validate: function(validator, $field, options) {
- var value = $field.val();
- if (value === '') {
- return true;
- }
- if (!$.isNumeric(value)) {
- return false;
- }
- var compareTo = $.isNumeric(options.value) ? options.value : validator.getDynamicOption($field, options.value);
- value = parseFloat(value);
- return (options.inclusive === true || options.inclusive === undefined)
- ? {
- valid: value >= compareTo,
- message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.greaterThan['default'], compareTo)
- }
- : {
- valid: value > compareTo,
- message: $.fn.bootstrapValidator.helpers.format(options.message || $.fn.bootstrapValidator.i18n.greaterThan.notInclusive, compareTo)
- };
- }
- };
- }(window.jQuery));
|