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

Default Values Using Javascript

Hi Everyone,

I have a form that has 2 choice controls that are being used as 'tabs'.

I need each choice control to default to 'Job Details' every time the form is opened.

It seems I need more than just setting their default values and have tried the below code:

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

var tab = NWF$("#"+mainTabButton);

tab.val('Job Details');

});

My goal is to have 'mainTabButton' (Client ID for JavaScript) and my 'AuthTab' (Client ID for JavaScript) to default to the value of 'Job Details' everytime the form is opened.

Pointers:

- Both 'tab' controls are choice controls on the form

- Both 'tab' controls are not connected to a list item (they are used for tab purposes only)

- Both 'tab' controls have JS Client ID names saved in their advanced options

I no longer get any debugging error messages with the code above, however it does not work. No errors, and no sign of anything happening.

Hope someone can help me

Regards,

Andrew

Labels: (1)
Tags (1)
Reply
19 Replies
Workflow Hero

Re: Default Values Using Javascript

I should mention in addition - the choice controls do have a default value. This works fine when the form is first opened - New Item.

Once the form is saved however the tabs (choice control) takes the value of the selection it was in when it was saved. I would like to set the value of these choice controls when the form opens.

Thank you.

Andrew

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Default Values Using Javascript

Hi Andrew,

The JavaScript code is not executed when you View the item but when you Edit the item.

You can also set the value when you Save the form to make sure when the item is opened, the default tab is 'Job Details'

Please refer to this Article to know how to do it.

Best regards,

Christophe Raucq

Accept as Solution Reply
Workflow Hero

Re: Default Values Using Javascript

Hi Christophe,

I have tried your code, matched up all of my fields and it doesn't currently work.

In F12 Debug mode - on the Console, it says I'm missing method=POST so it will not complete my task.

Do you have any ideas about this issue? Did you encounter it also on your way to making your code work?

Thank you,

Andrew

0 Kudos
Accept as Solution Reply
Not applicable

Re: Default Values Using Javascript

HI Andrew,

Assuming that you have set your Choice controls 'Display Format' to 'Option buttons', you can use the below code in document ready.

NWF$(':radio[value="Test1"]').attr('checked',true);

where Test1 will be 'Job Details' in your case. This will always force it to select 'Job Details' every time your form loads.

Give it a try and let me know how you go.

Jeremy

Accept as Solution Reply
Workflow Hero

Re: Default Values Using Javascript

Hi Jeremy,

Thank you for the hint.

What I find very strange is that when I put this JavaScript code behind a button in Edit mode, it sets my radio button to the right value when the radio button has no value.

But if I select another value, it does not reset to the value specified in this code. Do you know why?

Thanks,

Christophe

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Default Values Using Javascript

Hi,

I have been successful with the code 'NWF$(':radio[value="Test1"]').attr('checked',true);'.

Thanks for your help Jeremy, I was hoping you'd get in touch as I had followed your 'tab tutorial' so you probably have a good idea of what my form is like and the tabs I created. You were spot on, the display format is options buttons and the code works.

The form now sets its tabs to 'job details' on opening the form each time.

Thank you.

Best Regards,

Andrew

Accept as Solution Reply
Not applicable

Re: Default Values Using Javascript

Hi Chris,

Try to uncheck everything and then check the particular value which you want on edit button click. Example as below:

var rad = NWF$('#' + mychoice); 

    rad.find('input').each(function(){

           this.checked = false; //loop: uncheck all the selections

     });

// then select the first item which is the value I want selected.

rad.find('input')[0].checked = true;

Put this code inside your button click function.

Accept as Solution Reply
Workflow Hero

Re: Default Values Using Javascript

Thanks for checking but the issue is the last line as I would like to be more generic and use a value ('Job Details') instead of an index: 0

0 Kudos
Accept as Solution Reply
Not applicable

Re: Default Values Using Javascript

Hi Chris,

   You could just uncheck all and then loop thru the radio button values and check the item based on the value. Snippet as shown below:

   var rad = NWF$('#' + mychoice); 

    rad.prop('checked',false);

    rad.find('input').each(function(){

         if(this.value == "Test1"){

            this.checked = true;

         }

    });

Thanks

Jeremy

Accept as Solution Reply