Dynamic choices in a Choice list?


Badge +8

I placed a regular (non sharepoint ) choice field in a repeating section.   I would like to make the choices dynamic.   I populated the choices using some jQuery.   What works fine.   But when I go to  save the form, I get a "Something went wrong" error.

I found that if I enter one of the "dynamic" choices into the field's list of choices, I do not get the error.   So it seems the selection needs to preexist in the list of choices so it can be selected.

Am I going down the wrong path?   I do see how you can enter formulas for each choice but it seems to be for each individual choice as opposed to a list of choices.

P.S.   I am trying to use a dropdown list as my choice type.


12 replies

Userlevel 5
Badge +14

you will have to probably do something similar like mentioned in this comment https://community.nintex.com/message/34492#34492

ie. to set value of two HTML elements

Badge +8

What you're encountering in an error where the view-state is invalidated because of the values in the choice controls being manipulated on the client-side.

If you take a look at my last response in this thread, I shared the code used to work-around this problem. It involves calling a function when save is clicked to populate a single-line textbox with your choice-control's value and disabling the choice control in order to persist the data to your list without error.

NCAA bracket in Nintex Form

Good luck!

Badge +8

Thanks,  I am having a lot of trouble following that thread.   I am still trying to get used to this forum layout.

Is this the post you mean?   I don't understand how to implement this.  Can you please be more specific in your answer?   I am still getting started in this whole Nintex thing.

Do I just place this in my button's Client Click property?   How do I callit?

.

var dropDowns = {

    // Update a single-line text-box with drop-down's selected value

    populateTextBox: function (labelID, dropdownID) {

        var obj = NWF$('#' + labelID);

        obj.val(NWF$('#' + dropdownID + ' option:selected').text());

    },

    // Disables all choice controls based on CSS class

    disableAll: function () {

        NWF$('.gameSelection').prop('disabled', true);

    }

}

Badge +8

Thanks but I am not seeing how this pertains to my issue.   I am not trying to set a default value and if I am reading the thread right, I am not trying to use a lookup list.

Userlevel 5
Badge +14

it looks that from certain forms release (the most probably one when lookup manipulations in on/after-ready events stopped working) some form controls are backed by 2 (or maybe more?) HTML elements, one is for visual presentation and second one to be posted. if you set only one of the two it doesn't work correctly. (it's at least my understanding from my own experience)

just wanted to give you hint to check whether choice control wasn't redesigned similar way.

Badge +8

Right – You'd want some jQuery on your Save/Submit button's Client click property to perform the two functions above:

Screen Shot 2016-03-17 at 12.37.11 PM.png

You'd disconnect your dropdown from your list column and instead associate it with a textbox that you update with the populateTextBox function. After using jQuery to update this textbox, you then disable the choice controls so your error goes away when the save button is clicked.

Badge +8

I got the disabled part OK.    I am still lost at how the values get to the  text text box.   Can you give an example of how to call this inside the button's onCLick?  The dropdown is in a repeating section.   Do I need a text box in the repeating control too?   How would it know which dropdown to put in which textbox?

P.S.   My choice control is not connected to any sharepoint field other than the main field for the repeating section XML results.

Badge +8

Do you have a way of knowing what the clientID will be for the choice control in the repeating section? For the above solution to work, you'd need a textbox in each of the repeating sections and be able to access these via CSS class or JS clientID despite being dynamically generated with the repeater.

Badge +8

I do not.    I was hoping you could tell me. wink.png

I understand how it could work outside a repeating section.   Just don't know how to get the ID when they are inside the section. I know that NWF.FormFiller.Events.RegisterRepeaterRowAdded   passes an argument.   Don't know if there is a way to get it from there.

Badge +8

Actually, it would be great to be able to get a handle to the controls in all of the "new" repeating sections. 

Badge +8

You might try setting that control to "store JavaScript clientID" and then inspect rows 2+ using Chrome developer tools in your form to see if that ID can be predicted (i.e. myID_01, myID_02, etc.).

Userlevel 5
Badge +14

here you can find an example how to determine which row of repeating section a control is in, and how to determine single controls within the same row

Current row in repeating section nintex forms

Reply