cancel
Showing results for 
Search instead for 
Did you mean: 
Workflow Hero

Can I make One field change another field or the opposite?

Jump to solution

I know the title only creates more questions... let me elaborate. We are building a supply request form that is used in Kuwait. Because of this, the unit cost may be in U.S. Dollars (USD) or it may be in Kuwaiti dinar (KD). Lets suppose the exchange rate is 3.290 KD to 1.00 USD; if I enter 329.00 USD in the "Estimated Unit Cost-USD" field, I want 100.000 KD (yes, the KD is rendered in 3 decimal places) to show up in the "Estimated Unit Cost-KD" field. Alternatively though, if we receive an estimate in KD and I enter 100.000 KD into the "Estimated Unit Cost-KD" field, $329.00 should show up in the "Estimated Unit Cost-USD" field.

So, I want neither field to be a calculated value so that we can enter values manually in either.

Finally, I want the "Total Estimated Cost..." fields to calculate the respected unit cost values times the requested quantity value.

Any thoughts?

Thanks and Regards,

Patrick

Labels: (2)
Tags (1)
0 Kudos
Reply
18 Replies
Workflow Hero

Re: Can I make One field change another field or the opposite?

Jump to solution

Hi Patrick,

more questions ..

What happens when the user enters value on both the fields? Where do you pick up the exchange conversion rates from to do your calculation ( I am assuming exchange rates will change on a daily basis?)

Why would you not want to have a calculated value that gives you the conversion depending on which value is filled?

Regards,

Shrini

Reply
Workflow Hero

Re: Can I make One field change another field or the opposite?

Jump to solution

Hi Shrinivas Naik‌!

Thanks for the response!

Shrinivas Naik wrote:

Where do you pick up the exchange conversion rates from to do your calculation ( I am assuming exchange rates will change on a daily basis?)

We use a general exchange rate per contract period and we may, down the road, put in a feature to update it on the fly but the actual rate is arbitrary for this use case. We will hard code it at this point. Also, if we do use a dynamic exchange rate, we would not want it to change every time the form opened so that an older request would only reflect the estimate that was calculated when the request was created.

Shrinivas Naik wrote:

...What happens when the user enters value on both the fields?...

The current tool in InfoPath just changes the opposing field, so if I enter a value in USD, it updates the KD, then if I enter a value in KD it changes the value in USD.

Shrinivas Naik wrote:

...Why would you not want to have a calculated value that gives you the conversion depending on which value is filled?

The customer likes the way the two options just fill out the other.

Thanks and Regards,

Patrick

0 Kudos
Reply
Workflow Hero

Re: Can I make One field change another field or the opposite?

Jump to solution

Hi Patrick,

OK .. i will give you a quick solution to this .. hopefully it should solve your purpose. 

Do note that the event will trigger when the user adds the value (either USD or KD) and when he clicks outside or on the "lostfocus" event of the control.

Configure the following - 

USD Text box -

name - txtUSD

JS variable - varUSD

KD text Box

name - txtKD

JS Variable - varKD (JS variable is configured in the text box control properties -> advanced settings - >  "Client ID Javascript varibale name"

Form variable

1) Name - ProcessKDChange

where txtKD - > named control for KD

2) processUSDChange

where txtUSD -> named control for USD

Javascript 

- add the following JS to your form (form settings -> Custom javascript)

function processUSDchange(value) {

var someval = NWF$("#" + varUSD).val() * 2;
NWF$("#" + varKD).val(someval);
}

function processKDchange(value) {

NWF$("#" + varUSD).val(NWF$("#" + varKD).val());
}

Note - I haven't done the calculation and will leave that to you to complete it as I believe you would have got the gist of it and it would set up the plumbing required for you to change and control on other controls lost focus.

Regards,

Shrini

Please mark the answer as correct if it helps you answer your query , it will help other community members looking for a similar solution.

Reply
Workflow Hero

Re: Can I make One field change another field or the opposite?

Jump to solution

Hi Shrinivas Naik‌,

I tried your solution and here is the error I got when the form opens.

Also, the controls do not update when they lose focus.

Here is an example of the configuration of the controls...

Here is the copy/past of the code...

function processUSDchange(value) { var someval = NWF$("#" + varUSD).val() * 2;
NWF$("#" + varKD).val(someval);
}
function processKDchange(value) { NWF$("#" + varUSD).val(NWF$("#" + varKD).val());
}

Here are the Form variable configurations...

and...

I must add that the controls are in a repeating section. Should that make a difference? The form can have more than one item added to it.

Thanks and Regards,

Patrick

0 Kudos
Reply
Workflow Hero

Re: Can I make One field change another field or the opposite?

Jump to solution

Hi Patrick,

This will work if its a stand alone  control. You can try to create a simple list and add two controls and add the functionality. It will definitely work as I have tried it and gave you the snippet.

"I must add that the controls are in a repeating section. Should that make a difference? The form can have more than one item added to it."

This completely changes the scenario as you cant have the JS value attached to the textbos which is inside a repeater control, You can access values in the repeater control using CSS class. I will show you some script that you can use. You would have to "harden" the code so that the function should be called either before the form submits. Repeater control has only limited events where you can wire up, it wont work on "lostfocus" of the control.

The event which I am showing below is RowAdded event, but you would need to call the function even before submitting the form as the user can change the value of the control after the row is added. Please check the following for list of all repeater events 

JavaScript events in Nintex Forms 

Ex - 

1) Add CSS class to the repeater class 

2) COnfigure css class for both your USD and KD text boxes inside the repeater

3) Add the following JS

NWF.FormFiller.Events.RegisterRepeaterRowAdded(function () {

setExchangeRates('true');

});


function setExchangeRates(value)
{
var index, len;
var USD, KD;
var repValues = NWF$(".currencyrp .nf-repeater-row ");

//IGNORE FIRST HEADER ROW
for (index = 1, len = repValues.length; index < len; ++index)
{

USD = NWF$(repValues[index]).closest(".nf-repeater-row").find(".rpUSD input").val();
KD = NWF$(repValues[index]).closest(".nf-repeater-row").find(".rpKD input").val();

if ((typeof(USD) === "undefined") || (USD === null) || (isNaN(USD)) || (USD === ""))
{} else {NWF$(repValues[index]).closest(".nf-repeater-row").find(".rpKD input").val(USD * 2);}

if ((typeof(KD) === "undefined") || (KD === null) || (isNaN(KD)) || (KD === ""))
{} else {NWF$(repValues[index]).closest(".nf-repeater-row").find(".rpUSD input").val(KD / 2);}

}
}

NOTE - Following things to note..

1) This event or calculation will be fired only when you click the New repeater row

2) setExchangeRates() -- > Call this function again at the end when you are trying to submit the form so that it does a recalcutaion of all the values.

HTH..

Regards,

Shrini

Reply
Workflow Hero

Re: Can I make One field change another field or the opposite?

Jump to solution

Patrick Kelligan‌ Did that work for you?

Reply
Workflow Hero

Re: Can I make One field change another field or the opposite?

Jump to solution

Hi Shrinivas Naik‌,

I have been underwater with other tasks. I will try and work on this this week. Thanks for the response!!

Patrick

0 Kudos
Reply
Workflow Hero

Re: Can I make One field change another field or the opposite?

Jump to solution

Hi Shrinivas Naik,

I am working on this again and I wanted to ask if I was supposed to remove the previous code (see code block 1) as well as the Form variables (processUSDchange and processKDchange) or keep them?

 function processUSDchange(value)
    { var someval = NWF$("#" + varUSD).val() * 2;
        NWF$("#" + varKD).val(someval);
    }
function processKDchange(value)
    { NWF$("#" + varUSD).val(NWF$("#" + varKD).val());
    }

As it stand now, the code does not seem to be working. I have commented out the first block of code and also tried it with the first block included.

Thanks and Regards,

Patrick

0 Kudos
Reply
Workflow Hero

Re: Can I make One field change another field or the opposite?

Jump to solution

Hi Patrick Kelligan‌,

Please remove the earlier block and only include the one I mentioned in my last post as in my first post I did not know you were using the repeater control.

For clarity sake would you like to actually try it out on new form so that it does not clash with your existing stuff and once you see what works it will then be easier for you to troubleshoot.?

Regards,

Shrini

Reply