Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Decimal comma & nuDebug() Entries

Questions related to using nuBuilder Forte.
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Decimal comma & nuDebug() Entries

Unread post 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
You do not have the required permissions to view the files attached to this post.
ahernandez
Posts: 49
Joined: Thu May 03, 2018 12:08 pm

Re: Decimal comma & nuDebug() Entries

Unread post 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');
}
ahernandez
Posts: 49
Joined: Thu May 03, 2018 12:08 pm

Re: Decimal comma & nuDebug() Entries

Unread post 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.
ahernandez
Posts: 49
Joined: Thu May 03, 2018 12:08 pm

Re: Decimal comma & nuDebug() Entries

Unread post 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.
ahernandez
Posts: 49
Joined: Thu May 03, 2018 12:08 pm

Re: Decimal comma & nuDebug() Entries

Unread post by ahernandez »

sorry

I'm stealing you a lot of time and it does not seem right.
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Decimal comma & nuDebug() Entries

Unread post 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.
ahernandez
Posts: 49
Joined: Thu May 03, 2018 12:08 pm

Re: Decimal comma & nuDebug() Entries

Unread post 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.
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Decimal comma & nuDebug() Entries

Unread post by admin »

.
Post Reply