Dropdown list with default value

Hi,

In Bonitasoft studio, I click on my dropdown list widget, and go to Data> Available values. In Available values, I have a script where I’m getting a list of groups and sorting the values in ascending order. I want to be able to have a value like ‘Select options’ or an empty value, if possible, in my dropdown list. In Bonitasoft Studio, I have added a value like ‘Select options’ under Data>Selected value. Also, in Bonitasoft Portal, I’ve added this value under Groups. However, because I’m sorting my groups in ascending order, the value, ‘Select options’ is at the bottom of the list. How can I move this option at the top? Also, how can I make the dropdown list mandatory with a condition? I understand, in Bonitasoft studio, when I click on the widget, under Options, there’s a ‘Is mandatory’ checkbox. However, even though this will make the widget required, it will not stop the form from submitting because this widget will always contain a value. I do not want the user to be able to complete the form, if the dropdown list has ‘Select option’ as a selected choice. I want to be able to say, 'If the value is ‘Select options’, make widget required.

There are essentially 2 ways of preventing a form being submitted when it contains some combination of values you want to reject.

1: By using an expression in the “Disabled” field of the submit button. The traditional one is “$form.$invalid” which is true if any of the form fields contain invalid values (eg: a required field is blank). Another way is to define a form variable of type “javascript expression” to be true when you want to disable the button, and then refer to this variable in button’s “Disabled” configuration as an “fx” expression.

2: The better (safer) way is to handle it in the contract constraints in the server. If you want to do this, configure a variable to contain the error message for the submit button, and arrange for it to be displayed on screen if not empty. This is “safer” because non-compliant values cant be pushed into the server, even by someone bye-passing the javascript checks in the form.

So … lets say the value from your drop down is passed back in the contract field “selected_value”. Then…

a) define a contract constraint like: return selected_value != “Select options”.
b) define an error message for the constraint like: “Please select an option”.
c) In the form, define a variable: errorMessage
d) name the errorMessage variable in the “Failed response value” field of the submit button.
e) Place a text field on the form with a value like: {{ errorMessage.message }}
{{ errorMesage.explanations }}
f) Configure the “Hidden” value of the text field to be an “fx” expression with the value: !errorMessage

[[ Please click the tick if you like this answer ]]

Thanks chris.lowth for you quick reply. I do not want to disable the submit button. I want to make the field required with a valid option. So, I know I can make a field required by checking the “Is Mandatory” checkbox, however, this only works if there’s no values in the field. With a drop-down list, there will always be a value in the field. I’m just wondering if there’s some sort of expression I can write in ‘Selected value’ to handle this. You may have answer this with option 2 in your response, however, I’m not sure what you mean by contract constraints in the server or how to do that.

Also,chris.lowth, I’m using version 6.3 so is the constraint capability available in this version?