Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Enabling/disabling form fields
Enabling/disabling form fields [message #1284497] Fri, 04 April 2014 14:52 Go to next message
davide . is currently offline davide .Friend
Messages: 12
Registered: March 2014
Junior Member
Hello there. In my application I'd like to enable or disable (content gets "greyed-out" or maybe change buttons icons, ...) some form fields according to business logic. for example, when I open a form to insert data for a new db record, I'd like to disable or hide the id field. But using the same form I'd like to show the id field when the very same form is opened to view or modify a db record.
In a similar way I'd like to enable/disable or show/hide some other input widgets (buttons, text fields, ...) or group of widgets according to user input or click.

How can I accomplish this in scout forms?
thanks in advance

[Updated on: Fri, 04 April 2014 14:53]

Report message to a moderator

Re: Enabling/disabling form fields [message #1285243 is a reply to message #1284497] Sat, 05 April 2014 10:16 Go to previous messageGo to next message
Bertin Kiekebosch is currently offline Bertin KiekeboschFriend
Messages: 330
Registered: August 2011
Senior Member
In a Form you can get any field and then use setEnabled(false);

Examples

getIdField().setEnabled(true);
getFisrtNameField().setEnabled(false);

Hope this is what you mean.
Re: Enabling/disabling form fields [message #1290953 is a reply to message #1285243] Thu, 10 April 2014 15:30 Go to previous messageGo to next message
davide . is currently offline davide .Friend
Messages: 12
Registered: March 2014
Junior Member
Bertin, thanks for your answer.
Yes, I've got it and I did found the enabled properties of fields. But my question was about the architecture of scout: where are the code you wrote supposed to be put? Keep in mind that I want these fields greyed out (not enabled) when form is opened to input a new entity, and not greyed out (enabled) when the *same* form is opened to edit an existing entity (loaded from db).
thanks in advance!
Re: Enabling/disabling form fields [message #1291105 is a reply to message #1290953] Thu, 10 April 2014 18:16 Go to previous messageGo to next message
Bertin Kiekebosch is currently offline Bertin KiekeboschFriend
Messages: 330
Registered: August 2011
Senior Member
Hi,

if I need controles to be enabled or disable I normally create a enableControls() routine in which the controls are enabled or disabled and call it after the formadata is imported in the form.

Regards Bertin

  public class NewHandler extends AbstractFormHandler {

    @Override
    public void execLoad() throws ProcessingException {
      ITestResultaatProcessService service = SERVICES.getService(ITestResultaatProcessService.class);
      TestResultaatFormData formData = new TestResultaatFormData();
      exportFormData(formData);
      formData = service.prepareCreate(formData);
      importFormData(formData);
      enableControls();
    }
  }
Re: Enabling/disabling form fields [message #1291756 is a reply to message #1290953] Fri, 11 April 2014 07:31 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
You can have 2 handlers in you form (NewHandler and ModifiyHandler).

In the execLoad() method of each handler you can call your enable/not enabled logic.
As Bertin wrote, the logic can be packed in a method that is called with some paramter (isNew as boolean for example).

If you need to enable/disable all fields of a form or of a groupBox you can also call setEnable(boolean) of the form or of the group box.
Re: Enabling/disabling form fields [message #1293420 is a reply to message #1291756] Sat, 12 April 2014 16:23 Go to previous messageGo to next message
Bertin Kiekebosch is currently offline Bertin KiekeboschFriend
Messages: 330
Registered: August 2011
Senior Member
The fact that a field is enabled or disabled in our application often depends on some business rules that are executed on the server. I don't know if it is the right way to do it but it works for our appliaction.

On the form I add an array:
  private ArrayList<String> m_enabledFields;

and the method for enabling the fields (called in the execLoad() )
  public void enableControls() {
    // Enable all true formFields (not buttons). That is everything on the form that ends with "Field"
    ArrayList<String> enabledFields = getEnabledFields();

    IFormField[] formFields = getAllFields();
    for (int i = 0; i < formFields.length; i++) {
      IFormField ff = formFields[i];
      if (ff.getFieldId().endsWith("Field")) {
        ff.setEnabled(enabledFields.contains(ff.getFieldId().substring(0, ff.getFieldId().length() - 5)));
      }
    }
  }


On the server we create and fill the array with all the fields that must be enabled, example:
    ArrayList<String> enabledFields = new ArrayList<String>();
    enabledFields.add(testResultaatFormData.getAantalFout().getFieldId());
    ...
    ...
    formData.setEnabledFields(enabledFields);


I know it is a little tricky because it works on the fieldId but for us it works.

Regards Bertin
Re: Enabling/disabling form fields [message #1339238 is a reply to message #1293420] Wed, 07 May 2014 15:35 Go to previous message
davide . is currently offline davide .Friend
Messages: 12
Registered: March 2014
Junior Member
Thanks Bertin, interesting solution. I'll give it a try

[Updated on: Wed, 07 May 2014 15:35]

Report message to a moderator

Previous Topic:How to use SVG information in Jasper Report?
Next Topic:single form application: updating tables
Goto Forum:
  


Current Time: Tue Mar 19 05:45:53 GMT 2024

Powered by FUDForum. Page generated in 0.04855 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top