Sha256: 63b84d8c39490c5dd098cc816dd03a104adbc4ee0f81b3f1210b5408fd5103df

Contents?: true

Size: 1.25 KB

Versions: 39

Compression:

Stored size: 1.25 KB

Contents

/* global $ */
/* this is an example for validation and change events */
$.fn.numericInputExample = function () {
	'use strict';
	var element = $(this),
		footer = element.find('tfoot tr'),
		dataRows = element.find('tbody tr'),
		initialTotal = function () {
			var column, total;
			for (column = 1; column < footer.children().size(); column++) {
				total = 0;
				dataRows.each(function () {
					var row = $(this);
					total += parseFloat(row.children().eq(column).text());
				});
				footer.children().eq(column).text(total);
			};
		};
	element.find('td').on('change', function (evt) {
		var cell = $(this),
			column = cell.index(),
			total = 0;
		if (column === 0) {
			return;
		}
		element.find('tbody tr').each(function () {
			var row = $(this);
			total += parseFloat(row.children().eq(column).text());
		});
		if (column === 1 && total > 5000) {
			$('.alert').show();
			return false; // changes can be rejected
		} else {
			$('.alert').hide();
			footer.children().eq(column).text(total);
		}
	}).on('validate', function (evt, value) {
		var cell = $(this),
			column = cell.index();
		if (column === 0) {
			return !!value && value.trim().length > 0;
		} else {
			return !isNaN(parseFloat(value)) && isFinite(value);
		}
	});
	initialTotal();
	return this;
};

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
wbase-0.3.20 lib/vendor/admin/tiny-editable/numeric-input-example.js
wbase-0.3.19 lib/vendor/admin/tiny-editable/numeric-input-example.js
wbase-0.3.18 lib/vendor/admin/tiny-editable/numeric-input-example.js
wbase-0.3.17 lib/vendor/admin/tiny-editable/numeric-input-example.js
wbase-0.3.16 lib/vendor/admin/tiny-editable/numeric-input-example.js
wbase-0.3.15 lib/vendor/admin/tiny-editable/numeric-input-example.js
wbase-0.3.14 lib/vendor/admin/tiny-editable/numeric-input-example.js
wbase-0.3.13 lib/vendor/admin/tiny-editable/numeric-input-example.js
wbase-0.3.12 lib/vendor/admin/tiny-editable/numeric-input-example.js
wbase-0.3.11 lib/vendor/admin/tiny-editable/numeric-input-example.js
wbase-0.3.10 lib/vendor/admin/tiny-editable/numeric-input-example.js
wbase-0.3.9 lib/vendor/admin/tiny-editable/numeric-input-example.js
wbase-0.3.8 lib/vendor/admin/tiny-editable/numeric-input-example.js
wbase-0.3.7 lib/vendor/admin/tiny-editable/numeric-input-example.js
wbase-0.3.6 lib/vendor/admin/tiny-editable/numeric-input-example.js
wbase-0.3.5 lib/vendor/admin/tiny-editable/numeric-input-example.js
wbase-0.3.4 lib/vendor/admin/tiny-editable/numeric-input-example.js
wbase-0.3.3 lib/vendor/admin/tiny-editable/numeric-input-example.js
wbase-0.3.2 lib/vendor/admin/tiny-editable/numeric-input-example.js
wbase-0.3.1 lib/vendor/admin/tiny-editable/numeric-input-example.js