You can change Calx’s default behavior as you want by overriding default configuration value. The default configuration value comes with Calx is:
{ autocalculate : true, format : '0[.]00', readonly : true, language : 'en' round : 3 }
Format
By default, calx will use 0[.]00 as the default format, you can override it to another format as you want
$('#form_element').calx({ format : '$ 0,0[.]00' });
Language
The only language defined for number formatting is ‘en’, and it’s loaded by default, where it uses comma [,] as thousands delimiter, dot [.] as decimal delimiter, and dollar sign [$] as currency symbol.
To register your own language settings, simply call the Calx language method
$().calx('language',{ id : 'id', //id of the language, this sample is Indonesian format config: { delimiters: { thousands: '.', //the thousands delimiter decimal: ',' //the decimal delimiter }, abbreviations: { thousand: 'rb', million: 'jt', billion: 'M', trillion: 'T' }, ordinal : function (number) { return ''; }, currency: { symbol: 'Rp.' } } });
After new language settings was registered, you can call it when initializing the Calx:
$('#form_element').calx({ language : 'id' });
Autocalculate
By default, autocalculate value is true, it tells the Calx to trigger calculation automatically when form element ‘change’ event is triggered, to disable this, simply set the autocalculate value to be false
$('#form_element').calx({ autocalculate : false });
when the autocalculate value is false, no calculation result will be displayed when you change the form element value, until you call the Calx ‘update’ method
$('#form_element').calx('update');
Readonly
By default, Calx will mark all input element with data-formula attribute as readonly, you can change this default behavior by setting readonly value to be false
$('#form_element').calx({ readonly: false });
Round
When text box get focused, it will display it’s original value instead of formatted one which is usually float number with a lot of decimal digits. Since version 1.1.9 this behaviour can be controlled by round config to limit the number of decimal digits displayed when text box get focused
$('#form_element').calx({ round: 3 });
Hi there… maybe i made a mistake. Now ist running! Sorry for that comment.
Hi, i want to make a easy calculation site. But with German Settings. similiar then Indien here in this example. i have this Settings here but it didnt work. what is wrong in the initializing: is it the wrong place…
var currentRow = 1;
$(document).ready(function(){
$(‘#form_element’).calx({
language : ‘de’
});
$(‘#calx’).calx();
$(‘#add_item’).click(function(){
var $calx = $(‘#calx’);
currentRow++;
$calx.append(‘\
\
\
\
\
\
\
‘);
//update total formula
});
$().calx(‘language’,{
id : ‘de’,
config: {
delimiters: {
thousands: ‘.’,
decimal: ‘,’
},
abbreviations: {
thousand: ‘rb’,
million: ‘jt’,
billion: ‘M’,
trillion: ‘T’
},
ordinal : function (number) {
return ”;
},
currency: {
symbol: ‘Rp.’
}
}
});
$(‘#calx’).on(‘click’, ‘.btn-remove’, function(){
$(this).parent().parent().remove();
$(‘#calx’).calx(‘refresh’);
});
});
Hello,
Fantastic plugin! I am trying to round up to the nearest 0.5. Is there a way to do this at this point? Or a way to do an if/then statement that determines whether the last digit ends in a 5 or a 0? and round accordingly?
Thanks,
Alexa
Hi Alexa,
you can try this in data-formula section
Hi.
I have a query over the usage of `data-format=”0,0[.]00″`. When the focus is on the input field 3 zeros appear e.g. 24.000. Is there something I have to change in the data-format to just show round numbers? One of the calculations is $payYears * 12 which will always be in months……hope that query makes sense, if not let me know.
thanks
Nick
Just wanted to clarify something – the 24.000 goes back to 24 when the focus on the input field is lost (e.g. clicking away) 😉
Hi ,
I am trying to figure out how to make calx plugin understand the comma separated numbers . I have a logic which adds commas to the number as and when user enters in the input box , and the calx plugin is not calculating these values on fly. Can you please guide me how I can achieve this.
Thanks
Swathi
The configuration of readonly and round do not seem to work … Can you fix this or tell me a way to make it work please?!