cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
themos
Nintex Newbie

Generate button label dynamically from Form

Jump to solution

Hey guys,

This should be pretty straight-forward, but I can't seem to get it to work...

I want to change a button's label based on a condition (specifically, a radio-button choice control).

Here's what I tried adding on the button's label field:

fn-If(Decision Type == 'Meeting', 'Generate Documents with Notice', 'Generate Documents')

But for some reason, the button just renders the function in plain-text as-is!

I also tried adding a calculated field with the following (slightly different) formula, which worked as expected!

If(DecisionType == 'Meeting', 'Generate Documents With Notice', 'Generate Documents')

Before someone asks, I also tried using the "If" function instead of the fn-If, but still no luck

Does anyone know how I can implement this WITHOUT using javascript?

Labels: (2)
Reply
10 Replies
themos
Nintex Newbie

Re: Generate button label dynamically from Form

Jump to solution

OK I got it to work!

It seems it didn't like the == operator...

So I changed the function to fn-If(fn-Equals(Decision Type, 'Meeting'), 'Generate Documents with Notice', 'Generate Documents')

And also add a word-wrap: break-word; CSS style

EDIT:

Back to square one, the label value is static and doesn't seem to change regardless of the Decision Type radio-button value!

Is there a way to get it to change on the fly??

0 Kudos
Reply
themos
Nintex Newbie

Re: Generate button label dynamically from Form

Jump to solution

Any ideas about this?

0 Kudos
Reply
janeyres
Nintex Newbie

Re: Generate button label dynamically from Form

Jump to solution

Hi,

I've been having a go with this and I reckon the only way this could work would be to have 2 buttons, one on top of the other, that you can show/hide depending on the value selected in the named radio button control.

Jan

0 Kudos
Reply
themos
Nintex Newbie

Re: Generate button label dynamically from Form

Jump to solution

Hey Jan,

The problem with that solution is that I want to make further fn-If conditions if the decision type == 'Meeting', e.g. check the dates and decide if it's a Short Notice Meeting etc, and don't want to have to add additional buttons..!

I would also be happy if I could detect (via Javascript) the .change() event of the Calculated field and then assign its value to the button's label, but unfortunately the .change() event IS NOT TRIGGERED for labels!

0 Kudos
Reply
janeyres
Nintex Newbie

Re: Generate button label dynamically from Form

Jump to solution

Hi,

Could you move the logic from the calculated field to script? If you attach a change event to your select control (JavaScript id of jsDROPDOWN1) then you can change the button label depending on the value chosen.

NWF$(document).ready(function () {   
    NWF$("#" + jsDROPDOWN1).change(function(){
        var replacetext = '';
        switch (NWF$(this)[0].value)
        {
         case 'None':

      replacetext = 'One';
      break;

  default:

      replacetext = 'Two';
      break;

};

NWF$(".myButtonLabel input").prop('value', replacetext);
});

});

Jan

0 Kudos
Reply
themos
Nintex Newbie

Re: Generate button label dynamically from Form

Jump to solution

Hey Jan,

I wanted to avoid a JS-bound solution, as the If conditions are dependent on multiple controls (2 datetime pickers + 1 radio button, for now) and I didn't want to have to add .change() events to each control...

(the acceptable change I mentioned before was for a single .change() event, on the calculated field).

Here is what I have on the calculated field right now (which works correctly):

If(DecisionType == 'Meeting', If(isNullOrEmpty(ActualNoticePeriod), 'With No Notice', If(ActualNoticePeriod < NoticePeriodPerRegulation, 'With Short Notice', 'With Notice')), '')

0 Kudos
Reply
janeyres
Nintex Newbie

Re: Generate button label dynamically from Form

Jump to solution

Hi,

I've got this working using the calculated field now, if you give the calculated field a JavaScript id of jsCalculatedField then putting a delay in the change event of the select control does the trick.

NWF$(document).ready(function () {   
    NWF$("#" + jsDROPDOWN1).change(function(){

var delay=1000;
setTimeout(function() { 
    var replacetext = NWF$("#" + jsCalculatedField)[0].defaultValue;

           NWF$(".myButtonLabel input").prop('value', replacetext);
        }, delay);

   });

});

Jan

0 Kudos
Reply
themos
Nintex Newbie

Re: Generate button label dynamically from Form

Jump to solution

But you're still relying on the .change() event of the dropdown list...

What happens if the dropdown remains the same but the datetimepicker value changes?

The calculated value will change but your button won't!

0 Kudos
Reply
janeyres
Nintex Newbie

Re: Generate button label dynamically from Form

Jump to solution

If you apply a CSS class to each control you want to trigger the button label change then you can do it, I've used a class of changeTrigger. You'll need to get hold of each type of control in script and attach an appropriate event to it, sample code below:

NWF$(document).ready(function () {  

//select controls

NWF$(".changeTrigger select").change(function(){
    setLabel();
});

//date pickers

NWF$(".changeTrigger").find("input.nf-date-picker").each(function() {
    NWF$(this).blur(function(){
        setLabel();
    });

});

});

function setLabel() {
var delay=1000;
setTimeout(function() { 
var replacetext = NWF$("#" + jsCalculatedField)[0].defaultValue;

NWF$(".myButtonLabel input").prop('value', replacetext);
}, delay);
}

Jan

Reply