FormIO: Variables versus hidden fields

Hi,

working with Support on an issue with a JSON-form in IDM 4.9, I received the hint not to use hidden text-fields to hide values, which are needed for the logic of the form, but to use the new hidden component for this purpose.

Trying to use it, I run into the problem, my JS code is terminating, whenever I try to assign a value to a hidden component. So far I did not find a way to do this in the JS code, which is used to initialize all other fields/components.

What is working to use the calculated data property of a hidden component and set it to "value = someVariable", with the variable set by the JS code of the form.

Having such a variable defined, I am wondering, why it might make sense to assign the value to a hidden component or text-field. I guess this is only needed in case the value has to be send to the flowdata of the workflow later. OR is there any other reason?

But anyway. it would be nich to know jhow to set a value of a hedden componet in IDM 4.9.x.

The following code is  working for a text-field, but not the (new) hidden component:

instance.root.getComponent('hiddenAccountLockedOldValue').setFieldValue('true');

Kind regards

Thorsten

  • Verified Answer

    +1

    have you tried setValue method? it works for me, here an example I prepared some time ago for this forum: jsfiddle.net/.../

  • 0  

    I'm using the new hidden component for one customer, since after the upgrade to IDM 4.9 we couldn't use the old ones anymore (and it was easier to create a complete new one)

    I'm mostly using your way 'instance.root.getComponent('hiddenAccountLockedOldValue').setFieldValue('true');' to set fields.
    "instance.root.getComponent("hiddenValidationStatus").setFieldValue(htmlErrorContent)"

    Also: In the JSON I'm always having the following property: "clearOnRefresh": false

    Just for my understanding, how did you verify if this is not working? For debugging the hidden fields, I created a button with the simple custom action "console.dir(data)" to see what value my hidden fields are having. In additon, as far as I know (and what my colleagues told me) it is not possible to have this hidden fields in the payload, therefore in the workflow.

    Edit:

    Since you mentioned the "caluclated value". I'm using the following code in the "Custom default value".

    // data.hiddenRecipient -> DN-Value of a selected user (has its own logic how this hiddenField will be calculated
    // The code will set the value of the attribute "businessCategory" in the hidden field
    // I also set "clear value von refresh" on the hiddenField - therefore the value will be calculated everytime I select a new user
    
        IDVault.get('IDM','/rest/access/entities/list',data.hiddenRecipient, 'User', 'businessCategory')
        .then(function (response){
            //console.dir(response);
            if (response.businessCategory){
                
                instance.setFieldValue(response.businessCategory[0]);
                
            }
        })

  • 0 in reply to 

    I can confirm the setValue methode is working - but I guess the issue wa a typo in the API key in my code - sorry!

  • 0 in reply to   

    Hi Tobias,

    it is strange, but I found the setFiledValue() method is not working but the setValue() is - strange!

    But maybe there is a difference in the way you are accessing the componet and I do.

    I am using:

    instance.root.getComponent('hiddenAccountLockedOldValue').setValue('true');

    And in this case setFieldValue() is not working, if the form is refreshed!

    Cheers

    Thorsten

  • 0   in reply to 

    Hmm, I will be honest. For me the forms are sometimes a little bit of "dark magic". Sometimes a code is working for customer A but not customer B

    I will need to verify it again - but glad to hear that it works with "setValue"! Slight smile