-1

So, here is the problem. I am scripting in Groovy on a online Workflow platform. I have 9 forms containing custom fields. I have Edit action, in which I show/hide forms based on a type of product. Now, I have common fields, and I should show/hide them based on a type of product. For example: I have a custom field "Currency for cost", and it's on the form no.2. Which is ok if product is in A track. If product is in track B, it should be shown on a form no.5. Now, problem is, software doesn't allow field to be duplicated, neither the moveAfter, moveBefore. So, I hide all the forms except form no. 5 , but how to show just one custom field (Currency for cost) from form no. 2, without having to hide the rest of them in the code?

else if (step_to_editValue == 'costing') {
form.getWidget('customer_contact_information').hide();
form.getWidget('CAR').hide();
form.getWidget('product_questionnaire').hide();
form.getWidget('costing').show();
form.getWidget('complexity_review').hide();
form.getWidget('design_definition').hide();
form.getWidget('cost_estimation').hide();
form.getWidget('design_and_costing').hide();
form.getWidget('send_quote_to_customer').hide();
form.getWidget('check_quotation_status').hide();
form.getWidget('multi_pricing_screen1').hide();
form.getField('production_site').show();
}

So, "production_site" is on a 'complexity_review' form, but I want to show the 'costing' form + that one field from 'complexity_review'. If i do form.getWidget('complexity_review').show(); I would then need to hide all the fields, except one. Is there another way around, to just show that one field?

petkovicm
  • 1
  • 2

1 Answers1

1

Add a helper function:

void soloWidget(List<String> widgetNames, String showOnly) {
    widgetNames.each{ form.getWidget(it).hide() }
    form.getWidget(showOnly).show()
}

Keep a list of your forms and call that fn instead of copy and pasting:

def forms = ['customer_contact_information', 'CAR', ...]
// ...
soloWidget(forms, 'costing')

If your engine there has visual artefacts while aggressively hiding all and showing again, then add a (show|hide)Widget function, that deals with that and use it in showForm (e.g. ask the widget, if it's already hidden and don't hide again).

The important part: DRY! If you ever have the urge to copy-and-paste a block of code, don't!

cfrick
  • 35,203
  • 6
  • 56
  • 68