cancel
Showing results for 
Search instead for 
Did you mean: 

How do I dynamically set the readOnly attribute for a field property?

joeblue
Champ on-the-rise
Champ on-the-rise
I am trying to figure out how to dynamically set the readOnly attribute for several fields in a large form. My process and form are rather complicated, so I'm going to simplify it for this post:

My Users:
FormCompleter
FormReviewer

My Process:
Step 1: FormCompleter fills out the fields in the form.
Step 2: FormReviewer reviews the form and then indicates their approval/rejection of the form.

Both steps use the same form. In Step 2, I want to set the readOnly attributes to "true" for the form properties that the FormCompleter filled out in Step 1—i.e., in Step 2, the FormReviewer will not be able to edit any of the values entered by the FormCompleter in Step 1.

I believe I can use the formRendered JavaScript event to trigger this action. However, I have no idea how to access the readOnly attribute for a form property in JavaScript in order to change the readOnly value. (technically, I have no idea how to access the readOnly attribute at all because the only place I have seen the readOnly attribute is in the form's JSON file that I exported).


Please Note: Making a separate form for Step 2 using DisplayText and DisplayValue properties is a non-starter for me because my actual process and form can require up to 5 different users that need access to the form, each with different read/write privileges. I've seen this suggested as a solution to a similar problem on the Activiti.org forum, but I do not want to maintain 5 different versions of what is essentially the same form. I'd much rather just dynamically set the readOnly attributes when a user accesses the form.
2 REPLIES 2

anilmann
Confirmed Champ
Confirmed Champ
Did you tried over-riding of in-build types and rendering services?
I think that should resolve your problem.

For e.g. for text field you may be using "string" as form type. you can build your own type like "custom_string" and your own form rendering service which will handle the logic for edit/ready only mode. Rendering Java class can be a spring bean that have access to user information.

<java>
import org.activiti.engine.form.AbstractFormType;

public class TextAreaFormType extends AbstractFormType {

private static final long serialVersionUID = 1L;
private static final String TEXT_AREA_TYPE = "textarea";

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

public String getMimeType() {
  return "text/plain";
}

@Override
public Object convertFormValueToModelValue(String propertyValue) {
  return propertyValue;
}

@Override
public String convertModelValueToFormValue(Object modelValue) {
  return (String) modelValue;
}

}
</java>

<java>
import org.activiti.engine.form.FormProperty;
import org.activiti.explorer.ui.form.AbstractFormPropertyRenderer;

import com.jpmorgan.bpm.activiti.form.type.TextAreaFormType;
import com.vaadin.ui.Field;
import com.vaadin.ui.TextArea;

public class TextAreaFormPropertyRenderer extends AbstractFormPropertyRenderer {

private static final long serialVersionUID = 1L;

public TextAreaFormPropertyRenderer() {

  super(TextAreaFormType.class);

}

public Field getPropertyField(FormProperty formProperty) {

  TextArea textArea = new TextArea(getPropertyLabel(formProperty));
  textArea.setRequired(formProperty.isRequired());
  textArea.setEnabled(formProperty.isWritable());
  textArea.setRequiredError(getMessage("form.field.required", new Object[] { getPropertyLabel(formProperty) }));
  if (formProperty.getValue() != null) {
   textArea.setValue(formProperty.getValue());
  }

  textArea.setHeight("100px");
  textArea.setWidth("608px");

  return textArea;

}

}
</java>

joeblue
Champ on-the-rise
Champ on-the-rise

Thanks for the tip. I have not tried that, and I had to move on because I'm on a short schedule.

In the meantime, I'm just using different forms and using the Display Value fields in the second form. It's no fun keeping the forms in sync, but it was the best method given my time constraints.

I'll check out the override idea when I have a chance to refactor at a later time.