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

Questions related to using nuBuilder Forte.

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

Unread postby Olikun » Mon Apr 05, 2021 4:45 am

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?
Olikun
 
Posts: 48
Joined: Wed Mar 10, 2021 3:15 am
nuBuilder Version: 4.5

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

Unread postby kev1n » Mon Apr 05, 2021 4:30 pm

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();
kev1n
nuBuilder Team
 
Posts: 1625
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Previous

Return to General

Who is online

Users browsing this forum: absalom, GlenMcCabe and 28 guests

cron