How to show a single message with missing fields that are required.

6
I'm currently building a form with a lot of input fields that are required. But I don't want to set the "Required" property of this fields to "true", because showing the required messages underneath this fields changes the layout of my form. Instead I want to show a single message with a bullet-ed list of all the missing fields after the user presses the save button. How can I do this?
asked
4 answers
5

What you can do is construct a text message in a variable in a microflow. How to do:

Create a variable of type string.

Check if a field that is required is empty, if so change the variable with:

$Variable + ' - The X field is not filled in '

At the end of the microflow you can check if the message variable is empty. Of not, you can send a message to the client with the text in the message variable. There you can also add a text to make it a nice message;

'The following fields are requirerd: $variable '

answered
7

As the others have suggested, this can be achieved by using micro flows creating your own custom validation messages. However by doing this, you won't be able to use the Mendix internationalization options to translate the messages to the correct language.

If internationalization is important for your project and you really want this single validation message, you'll have to handle the translations yourself. Using micro flows, you could create a validation micro flow for each language in your project, and use the language settings of the current user to determine which one to use. Or you could do the validation using a Java action and use the Java internationalization classes (part of the Java SE core).

answered
5

Here is what I think you could do when you use invoke buttons for save and cancel:

  1. Create a invoke button on your datagrid.
  2. This button will replace your current 'save' button.
  3. Add a microflow to the invoke button.

In the microflow:

  1. Create a variable of type String.
  2. Create checks for every input if they are filled whith a value.
  3. When a value is empty: add a custom text to the String variable.
  4. If a value isn't empty go to the next check.
  5. If you checked all your inputs:
  6. Check if the variable string is empty or ''
  7. If the String is not empty show a message and don't save.
  8. If the String is empty then Save (commit)

Good luck.

answered
3

I think you'd be best of in this case by checking all your required fields in a Before Commit event, where you can save all incorrect fields into a variable or an object and show a 'Show Validation Message' window before returning a False on the microflow if any were incorrect.

answered