Dear Nintex community
I am starting my adventure with Nintex, JS and jQuery.
I've spent alredy few hours trying to find solution this but seems that I still missing the concept...
So what I have:
1. List on sharepoint with column "State"
2. In forms I've assigned as follows:
3. I've written this code in CustomJS field:
var Sstate = NWF$('#' + varState);
console.log("Sstate= " + Sstate + " Sstate.val()= " +Sstate.val()+ " Sstate.text()= " + Sstate.text() + " varState= " + varState);
4. and this is what I received in console log when I am opening the form:
Sstate= [object Object] Sstate.val()= undefined Sstate.text()= varState= ctl00_ctl54_g_2e434ee3_cc48_4bca_87f0_294c48339002_ctl00_ListForm1_formFiller_FormView_ctl38_cd490519_949d_48e6_90af_d0f96aacd0a9
What the hell I am doing wrong? :) Why I cant see nowhere in console log that the value of field State is "NH"? Please help! :)
Solved! Go to Solution.
Moving on, the reason you're having an issue is because of how Nintex Forms generates the Form in different modes.
I noticed that you're in View Mode on in your screenshot, and wouldn't ya know, Nintex Forms (which I will now refer to simply as "Forms") doesn't actually generate IDs and place them onto the elements! Though it still creates the variable that it's obligated to make, it puts a GUID inside of it that doesn't actually point back to any ID on an element! Yay!
That being said, there IS some useful information there if you know what you're looking for.
Notice how the parent Div Element (where the mouse pointer is) has an attribute called "data-controlname". See that value? That's the same name of the Control as given on the Form in the settings:
Because the name of the control is ALWAYS applied to the topmost level of a Control (the ONE exception being Panels... because they are silly), you can use it in more places and in a more reliable way than you can with the ID variables.
Using the name shown above ("slt_State"), you could use the following code to grab the value:
Now you should be able to get the value of your controls no matter which mode you're viewing the form in!
I hope this helps!
Additional Notes: There are a few other topics which may be of interest but necessarily relevant to your situation. I would just like to make you aware of them in the event that they come up.
I hope this isn't too overwhelming! Please ask more questions as they come to you!
@MegaJerk Thanks for the input, I just have a question left.
What I'm doing is copying the attachments from the task to the main item (via workflow) and updating the NFFormData of the item to position them correctly. I am now trying to do it the other way around : getting the attachments from NFFormData from the main item to display them at the correct position (with the control name) on my task form via JS.
I noticed that the datac-controlname is not generated for attachments on form, but the NFFormData is correctly saved after the submit of the form.
My question is : how is it possible to get the correct attachment control on a form with JS except via using a CSS class ?
I suppose it should be possible since Forms is doing some kind of mapping between "data-controlid" (or "formcontrolid") and "data-controlname".