How to change an attribute by Javascript in Single Line Textbox Control?


Badge +4

In Nintex forms I would like to create a key/value relation.

By Javascript I would like to store the key (e.g. with an attribute) and try to ask for this value by an if condition. (The value is the text of the TextBox). 

Always when the key has changed (condition), then the value should Change.

I tried it with this JavaScript function:

function lookupInTextField (key, value,  js_Text_ID)
{
      if (NWF$('#'+ js_Text_ID).attr("placeholder") != key )
      { 
           NWF$('#'+ js_Text_ID).val(value);
           NWF$('#'+ js_Text_ID).attr("placeholder", key);
           alert ("Key-Attribute: " + NWF$('#'+ js_Text_ID).attr("placeholder"));
      }

}

Unfortunately the alert-Output is always "Key-Attribute: undefined". Can somebody please give me a hint what I am doing wrong. Somehow it does not work with the placeholder Attribute of the "single line TextBox" control in Nintex forms.

I Trigger this function with the "Calculated fields" control. So far so good.

Does anybody know how to store the key and how to get the key?

Any help and hints are greatly appreciated!

Regards

Andy


6 replies

Badge +9

Hi Andreas,

function seems to be fine. How is this function called. Can You set a breakpoint and check that parameter values are OK?

Kind regards

Manfred

Badge +4

Hi Manfred,

yes the function works. Unfortunately, the control attribute (here the key "placeholder")  looses its value after closing the form and editing the form. Only the value of the text control is saved but not the attributes. :-(

Kind regards

Andy

Userlevel 5
Badge +14

this is not going to work.

with adding/updating an attribute you just change current DOM model of a page currently rendered. page DOM model has nothing to do with list item itself, so these changes are not saved anywhere and are not preserved across page instances.

if you want to save value of key you have to create dedicated control on a form. if you do not want users see it, you can hide it with rules.

you can (but need not) to connect control to dedicated list field, depends on what exactly you need to do with that key value.

Badge +4

Hi Marian

Thank you for the excellent explanation why it does not work with attributes.

Do you think that it also works with form variables. I would like to use them instead of controls which I have then to hide with rules. If possible do you know how to access them in Javascript. With the document.getElementByID-methode (here: document.getElementById(myFormVar))?

Kind regards

Andy

Von: emha

Gesendet: Freitag, 7. April 2017 09:25

An: Muss Andreas <Andreas.Muss@bdo.ch>

Betreff: Re: - Re: How to change an attribute by Javascript in Single Line Textbox Control?

Nintex Community <https://community.nintex.com/?et=watches.email.thread>

Re: How to change an attribute by Javascript in Single Line Textbox Control?

reply from Marian Hatala<https://community.nintex.com/people/emha?et=watches.email.thread> in Dev Talk - View the full discussion<https://community.nintex.com/message/60210-re-how-to-change-an-attribute-by-javascript-in-single-line-textbox-control?commentID=60210&et=watches.email.thread#comment-60210>

Userlevel 5
Badge +14

form variables are as well (re)initialized with every new instance of a form/page. so they are not saved either.

Badge +4

Okay. Thank you for the news. Then I will do the proposed way with the controls and rules.

Kind regards

Andy

Von: emha

Gesendet: Freitag, 7. April 2017 11:23

An: Muss Andreas <Andreas.Muss@bdo.ch>

Betreff: Re: - Re: How to change an attribute by Javascript in Single Line Textbox Control?

Nintex Community <https://community.nintex.com/?et=watches.email.thread>

Re: How to change an attribute by Javascript in Single Line Textbox Control?

reply from Marian Hatala<https://community.nintex.com/people/emha?et=watches.email.thread> in Dev Talk - View the full discussion<https://community.nintex.com/message/60211-re-how-to-change-an-attribute-by-javascript-in-single-line-textbox-control?commentID=60211&et=watches.email.thread#comment-60211>

Reply