How to set a form field to read-only on condition?

Confluence User - 21 Mar, 2017

I have a requirement where a particular field in a form need to be set to read-only, once the user populate it with a text/data and submit it (commit it to the database). The next time the form is displayed with existing data, the user cannot modify the field any more. I can achieve this by creating two forms: one form has the field NOTset to read-only so that the user can enter the data and submit. The other form has the same field set to read-only mode and used when the user retrieves the old record.

However this is like over-kill, as there are a lot of forms in my app and I have to duplicate them one by one just to  achieve this.

Is there any way to set read-only attribute of the field (e.g a text field) to read only dynamically in the same form when certain criteria is met?

forms

7


21 Mar, 2017
confluenceUser
1
confluenceUser

Try using Subform.

22 Mar, 2017
confluenceUser
confluenceUser

I have tried using subform. However that form is being used to enter data into a form grid, and it does not behave properly. The fields from the subform does not get populated back to the grid.

In the meanwhile, I am redesigning the form now and store  the values to be displayed read-only in a separate field, and use sections to hide and unhide the fields.

 

22 Mar, 2017
confluenceUser
confluenceUser

I have tried this method instead:Define a section where there are three fields (Value Date, Fund Type, and Quantity). I set the section attribute: Visibility to depend on another field on the screen, i.e. flag_prelocked. When launching the form, those three fields are not displayed on the screen. However when the form is submitted, their values become empty. Is this a normal behaviour, when the fields are located in a hidden section?

Thanks,

 

23 Mar, 2017
confluenceUser
confluenceUser

Maybe those 3 fields are empty all the while? "Field value to display this section" is left blank, perhaps it is expecting a value since you have filled up "field ID to control this section".

23 Mar, 2017
confluenceUser
confluenceUser

The fields are not empty initially. I have verified it in the table at the database itself. When I submitted the form, I checked the table at the database, all 3 fields become empty. My commonsense is that although the fields are hidden in the form, they should not be assigned empty value.

23 Mar, 2017
confluenceUser
confluenceUser

Can you provide us with minimal replicable joget app for further inspection? You can drop the .jwa file here. Thanks!

19 Oct, 2017
confluenceUser
confluenceUser

Hi Herman,

It's been 6 months, but I found it possible to make some field dynamically read-only through custom plugins by extending default WorkflowFormBinder.

I will share you the code, let's say you want to make field2 readonly, you can use:

public class MyWorkflowLoadBinder extends WorkflowFormBinder {
    @Override
    public String getName() {
        return "My Workflow Load Binder";
    }

    @Override
    public String getLabel() {
        return getName();
    }

    @Override
    public FormRowSet load(Element element, String primaryKey, FormData formData) {
        Element field = FormUtil.findElement("field2", element, formData);
        if(field != null)
            FormUtil.setReadOnlyProperty(field);
        return super.load(element, primaryKey, formData);
    }
}

The beauty is you can put this in either Forms or Sections, and I will just leave the rest to your imagination since you can almost do anything in the code (big grin)

Regards.

RELATED QUESTIONS

Your answer


To answer a question you'll need an account.

Print