Page 3 of 3
Re: Decimal comma & nuDebug() Entries
Posted: Sat May 26, 2018 5:25 pm
by toms
Place all code in the form's js code:
Code: Select all
function fixCommas(.....){
...
}
if (nuFormType() == 'edit') {
fixCommas(.....);
}
Then in the subform object, add an afterinsertrow event handler under "Custom Code" and call fixCommas(.....) too.
subf.PNG
Re: Decimal comma & nuDebug() Entries
Posted: Sat May 26, 2018 7:08 pm
by ahernandez
I have this code in 'afterinsertrow'
if ($('#opo_estado').val() == 'R' || $('#opo_estado').val() == 'N') {
$('#label_opo_comentarios').show();
$('#opo_comentarios').show();
} else {
$('#label_opo_comentarios').hide();
$('#opo_comentarios').hide();
}
if (nuIsNewRecord()) {
$('#label_opo_oportunidad').hide();
$('#opo_oportunidad').hide();
}
fixCommas('rsf_prevision', 'pre_facturacion');
fixCommas('rsf_prevision', 'pre_margen');
The call to fixCommas works only from the second row and just for the first field 'pre-facturacion'
The JS Code in the Form is this..
if (nuIsNewRecord()) {
$('#opo_fecha').val(fechaActual()).change();
$('#opo_probabilidad').val('B').change();
$('#opo_estado').val('O').change();
$('#label_opo_oportunidad').hide();
$('#opo_oportunidad').hide();
}
if ($('#opo_estado').val() == 'R' || $('#opo_estado').val() == 'N') {
$('#label_opo_comentarios').show();
$('#opo_comentarios').show();
} else {
$('#label_opo_comentarios').hide();
$('#opo_comentarios').hide();
}
function fixCommas(frm, field) {
var sf = nuSubformObject(frm);
for (var i = 0; i < sf.rows.length; i++) {
$('#' + frm + nuPad3(i) + field).attr('onchange', '').on('blur', function (event) {
$(this).val($(this).val().replace(',', '.'));
nuChange(event);
});
}
}
if (nuFormType() == 'edit') {
fixCommas('rsf_prevision', 'pre_facturacion');
fixCommas('rsf_prevision', 'pre_margen');
}
Re: Decimal comma & nuDebug() Entries
Posted: Sat May 26, 2018 7:19 pm
by ahernandez
I can type any number with comma or without, but when I click the Tab key to move to the next field the last turns blank.
Re: Decimal comma & nuDebug() Entries
Posted: Mon May 28, 2018 9:34 am
by ahernandez
And I have found the problem...
When I type for example 40,50 onblur event calls fixComma() and it converts this number to € 40,40. For some reason, automatically it calls again fixCommas() changing again € 40,40 by € 40.40, but this value with € inside is not valid and this is why the field turns blanks.
Although not so pretty, if I change the filed type to number instead nuNumber keeping the call to fixCommas() it works fine.
I do not know if it's worthwhile to continue investing time knowing that this works and waiting for the fix..
What's your opinion?
I'm stealing you a lot of time and I do not think it's bine.
Thank you toms.
Re: Decimal comma & nuDebug() Entries
Posted: Mon May 28, 2018 9:35 am
by ahernandez
sorry
I'm stealing you a lot of time and it does not seem right.
Re: Decimal comma & nuDebug() Entries
Posted: Mon May 28, 2018 9:53 am
by toms
ahernandez wrote:sorry
I'm stealing you a lot of time and it does not seem right.
This should fix it (prevents the blur event from being bound multiple times)
Code: Select all
function fixCommas(frm, field) {
var sf = nuSubformObject(frm);
for (var i = 0; i < sf.rows.length; i++) {
$('#' + frm + nuPad3(i) + field).attr('onchange', '').off('blur').on('blur', function (event) {
$(this).val($(this).val().replace('1', '2'));
nuChange(event);
});
}
}
My opinion: This should be fixed by the the nuBuilder Staff. My fixCommas() function is only intended as a workaround.
Re: Decimal comma & nuDebug() Entries
Posted: Mon May 28, 2018 11:03 am
by ahernandez
Thank you very much toms
Now works perfectly.
This allows me to continue with the development of the project.
Problem solved.
It is a great solution waiting for the official fix of nuBuilder.
Re: Decimal comma & nuDebug() Entries
Posted: Sat Jun 02, 2018 4:53 am
by admin
.