Welcome to the nuBuilder Forums!

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

Combine Calc-Field with Select-Field and Number-Field?

Questions related to using nuBuilder Forte.
Olikun
Posts: 68
Joined: Tue Mar 09, 2021 6:45 pm

Re: Combine Calc-Field with Select-Field and Number-Field?

Unread post by Olikun »

Hello,

a new question about the Spice Tool.


I recreated the Forumar from your demo, it worked
Demo (https://test.nubuilder.cloud/ login: test psw: nutest)


But there has been a change in my calculation and I need a new code for it
It's no longer about pepper or salt, it's just about salt

Image


I took the form code from the demo and adapted it.

It works, but I'm still not sure it's right.
I don't want there to be problems in the future.

Code: Select all

function myspices(){
var meat_weight=$('#1W12').val();
var spice_type = $('#1W11').val();

if (spice_type=='BBQ/Chili'){
     spice_weight = meat_weight * 0.2;
    $('#1W1M5').val(spice_weight).change();}

else if (spice_type=='Original') {
    $('#1W1M5').val(0).change();}
else {
    $('#1W1M5').val(0).change();
    }

}

Is the code so correct or is there a better one?
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:

Re: Combine Calc-Field with Select-Field and Number-Field?

Unread post by kev1n »

This should be the same, but simplified:

Code: Select all

function myspices() {

    var meat_weight = $('#1W12').val();
    var spice_type = $('#1W11').val();

    if (spice_type == 'BBQ/Chili') {
        spice_weight = meat_weight * 0.2;
    } else {
        spice_weight = 0;
    }

    $('#1W1M5').val(spice_weight).change();

}
or with a one-liner (less readable though)

Code: Select all

$('#1W1M5').val($('#1W11').val() == 'BBQ/Chili' ? $('#1W12').val() * 0.2 : 0).change();
Post Reply