2, $2, or $2.00 - all become $2.00 when you blur15, 15%, or 0.15 - all work! The formatter handles itdata-var="TAX" to create named variables that can be referenced in formulasHere's how to use formatters with input-mask behavior:
<!-- Currency input with mask - accepts 2, $2, $2.00 -->
<input data-cell="A1" value="1234.56" data-format="currency">
<!-- Named variable using data-var -->
<input data-cell="B1" data-var="TAX" value="0.08" data-format="percent">
<!-- Use the named variable in formulas -->
<input data-formula="A1*TAX" data-format="currency" readonly>
<!-- Percent input with mask - accepts 15, 15%, 0.15 -->
<input data-cell="A2" value="0.08" data-format="percent">
<!-- Readonly calculated field with formatting -->
<input data-formula="A1*1.08" data-format="currency" readonly>
<!-- Display-only element -->
<div data-formula="A1*A2" data-format="currency"></div>
<!-- Initialize Calx -->
<script>
$('#myform').calx({
autoCalculate: true
});
</script>
currency - Formats as $1,234.56 with thousand separators. Accepts: 1234.56, $1234.56, $1,234.56percent - Formats as 12.34%. Accepts: 0.1234, 12.34, 12.34%number - Formats with 2 decimal places (123.46). Accepts any numeric inputinteger - Rounds to whole number (100). Accepts any numeric inputtext - Converts to string representationInput-mask feature: All formatters intelligently parse your input, so you can type naturally!
Custom formatters: You can register your own formatters with parse() and format() methods!
Apply CSS styles based on cell values using data-style-if attribute:
negative - Applies red color when value < 0positive - Applies green color when value > 0zero - Applies gray color when value = 0Example:
<!-- Show negative profit in red -->
<input data-formula="REVENUE-EXPENSES"
data-format="currency"
data-style-if="negative"
readonly>
Custom style formatters: Register your own via JavaScript!
$('#myform').calx({
styleFormatters: {
warning: function(value, $element) {
if (value > 1000) {
return {
color: 'orange',
fontWeight: 'bold'
};
}
return {};
}
}
});