Input Field
The Input Field () is a form object for entering single-lined text.
Enter the name of the input field object in the Name field.
By default, the Editable check box is selected, so that users of the application can change the value in the input field. Clear the Editable check box to display the initial value as a read-only value.
In the Tooltip field, enter text that will appear as a tooltip when the user hovers the pointer over the input field. The input field objects also have a built-in tooltip that shows the entered text if it does not fit into the input field, or any error or warning.
In addition, the Settings window contains the following sections.
Source
In this section, you define the data source for the input field. The section contains a tree with a filtered view of the tree in the Application Builder window. The nodes either represent some sort of data or have children that do. For an input field, parameters and variables in the COMSOL Multiphysics model and scalar variables that you define under Declarations are available as the data source. You can extend the list of available data nodes by clicking the Switch to Model Builder and Activate Data Access button () in the Source section header, and then selecting a node in the Model Builder with data you want to access. With this button active, the Settings window of the selected node displays a Select Data Source check box (a green square) next to the settings that you can include. Click to select the check box to include the data as an available source node for input fields.
If the Editable check box is cleared so that the field is read-only, you can choose to use one of the following information nodes as the source. They are found under the main Model node and each Study node.
The Expected Computation Time node () under Model>Information (): The expected computation time is a value that you can enter in the Expected field in the Root node’s Settings window.
The Last Computation Time node () under Model>Information: This node shows the last measured computation time for the last computed study.
The Last Computation Time node () under each Model>Study>Information: This node shows the last measured computation time for the study.
When you start an application for the first time, the last measured times are reset, displaying Not available yet.
When you select a node that represents data, you enable the Use as Source toolbar button () below the tree. You can click it or, alternatively, press Enter, double-click, or right-click the node and choose Use as Source to add it as the selected source. You can also click the Create button () in the Source section header to create a new variable declaration and use it as the source. A Create and Use Variable dialog box opens, so that you can select the data type of the source (if applicable), its name, and its initial value (if applicable). The name cannot be in conflict with any existing variable declaration. Click the Edit Node toolbar button () below the tree to move to the corresponding node. If necessary, the program switches to the Model Builder.
After selecting a node as the source, the node appears as the selected source under Selected source.
From the Initial value list, select From data source to link this input field to the data source defined in the Source section and use the values specified by that source. From data source is the default setting for new input fields. Select Custom value to enter the initial value for the input field in the Value field. This value overwrites any value you specified for that string.
Data Validation
Use the settings in this section to validate user inputs with respect to units and values.
From the Unit dimension check list, choose one of the following options:
None (the default): No check is done of the unit or value.
Compatible with physical quantity: A check is done to make sure that the input’s unit is compatible with the physical quantity that you specify using the Physical quantity list underneath the Unit dimension check list. Click the Select Quantity button () to open the Physical Quantity dialog box to browse to find a physical quantity to use. You can also type a search string in the text field at the top of the dialog box and then click the Filter button () to filter the list of physical quantities. For example, type potential and click the Filter button to only list physical quantities that represent some kind of potential.
Compatible with unit expression: A check is done to make sure that the input’s unit is compatible with the unit expression that you specify in the Unit expression field underneath the Unit dimension check list. The user of the application gets the same type of information and handling as in the previous case if there is a unit mismatch.
Append unit to number: The application user can type in a number without appending a unit using the unit syntax with square brackets. The application appends the unit expression that you specify in the Unit expression field underneath the Unit dimension check list.
Append unit from unit set: The input field appends a unit from a Unit Set node added under Declarations (see The Unit Set Node). You specify the unit set to use from the Unit set list and the unit to use from Unit list, which lists all defined properties and their units from the select unit tests. There is also a No unit option.
When applicable, click the Add Unit Label button () to add a unit label linked to the input field and place it to the right of the input field.
For the options None, Append unit to number, and Append unit from unit set, you can also use a filter to validate the numerical input. Under Numerical validation, choose a filter from the Filter list:
None, for the None option only, where it is the default setting.
Double (the default for the Append unit to number option), for checking that the entered value is a floating-point number (double). Select the check boxes for Lower bound and Upper bound to specify a lower and upper limit, respectively, in the corresponding text fields. You can specify if the comparison to the limit should be Greater than or equal (the default) or Greater than (for the lower bound) and Less than or equal (the default) or Less than (for the upper bound) in the Comparison type lists. The limits can be numerical values, declarations, or expressions, including parameters defined in the global Parameters node’s Settings window. The limits dynamically change when the parameter values change. It is possible that, after a change in the minimum or maximum value, the value in an input field becomes temporarily invalid. If the parameter or expression for the minimum or maximum value does not have the same dimension as the unit entered in the Unit expression field, the parameter or expression appears in yellow, and a tooltip describes the unit mismatch. If the parameter or expression has the same dimension but another unit than the unit entered in the Unit expression field, a unit conversion to that unit occurs.
Integer, for checking that the entered value is an integer. Select the check boxes for Lower bound and Upper bound to specify a lower and upper limit (as integer values), respectively, in the corresponding text fields. The settings are otherwise similar to those for Double.
Regular expression (for the None option only), to use a regular expression for matching the input string and issue a custom error. Specify the expression to check against in the Regular expression field and the error message (default: Invalid input) in the Error message field.
The regular expression consists of a pattern that is matched to the user input. The pattern can contain ordinary characters and special characters. Special characters have a special meaning and do not represent themselves. The special character \ is used for quoting special characters to have those characters represent themselves; for example, \\ represents a backslash. When you use \ on ordinary characters, it makes them have a special meaning. For example, \t means a tab character, and \n means a newline character. The special character . (a dot) stands for any character. [abc] (characters in brackets) stands for any of the characters a, b, or c. [^abc] stands for any characters except for a, b, or c. (abc) (characters in parentheses) represents the sequence of characters abc. * (an asterisk) means repetition, including zero times. + (plus) means repetition, at least one time.
For a complete description of regular expressions, see the documentation of the java.util.regex class in Java.
Some examples:
-
a.c means the letter a followed by any character followed by the letter c.
-
[^ab]c means any character but a and b, followed by the letter c.
-
a*b+ means any number of the letter a (including zero occurrences) followed by at least one b.
In the Error message field, type an error message that appears if the data validation fails. You can include variables in the error message such that it can be dynamic and include the current value of parameters and declarations as well as the specified lower and upper bound. For example, in the following error message the lower and upper bounds are represented by MINVALUE and MAXVALUE, respectively: The radius must be greater than eval(MINVALUE) and less than eval(MAXVALUE).
It is also possible to access the old value and the new value in methods called from events so that they can be used when writing validation code and to access the new value when writing data validation code in dialog boxes that work on a copy of the data. See the Introduction to Application Builder for more information.
If you test the application using Test Application and a data validation error message occurs, the error message contains extra information about the type of form object and its path to help you locate the origin of the error message. The extra information does not appear when running an application through Run Application or COMSOL Server.
Position And Size
This section contains all layout settings for an input field in the grid of the parent form.
In the grid mode, you can control the horizontal and vertical alignment of the input field using the following lists:
From the Horizontal alignment list, choose Left, Center, Right, or Fill, which automatically expands the form object to fill the cell in the horizontal or vertical direction (where applicable).
From the Vertical alignment list, choose Middle, Top, Bottom, or Fill, which automatically expands the form object to fill the cell in the horizontal or vertical direction (where applicable).
The need to specify the alignment is most obvious when working in the grid mode, as it controls how the form object is aligned in its grid cell. Aligning the form object can be useful in the sketch mode too, and you can then use the alignment tools on the Arrange menu in the Form toolbar’s Sketch section. When running the application in any client other than the Windows client, the form objects may not be positioned exactly as seen in the Application Builder. This is because the form objects may have a different size in other clients, giving them a slightly different positioning. Specifying the alignment ensures that the form objects are aligned as you want them to be in all clients.
You can also specify the width of the input field. Enter a width (in points) in the Width field. If you have chosen Fill from the Horizontal alignment list, you can instead specify a Minimum width. Choose Automatic to compute the minimum width automatically (typically this means a minimum size of 0) or choose Manual to specify a minimum width in the text field underneath. The Height field is unavailable because the height of the input field is determined by the software.
Additionally, in the sketch mode, you can specify the absolute position of the input field using the Position x and Position y fields. In the grid mode, you can position the object in the grid and see the grid position as the Row, Column, Row span, and Column span values.
Cell Margin
Under Cell margin (in grid mode only), you can control the margins around the form object. By default, the margins are taken from the parent form. From the Cell margin list, choose:
None, for no margin around the form object
From parent form (the default), to use the margins set for the parent form
Custom, to specify the margins for the form object in the Horizontal and Vertical text fields
Appearance
In this section, you can control the appearance of the background and the text in the input field:
From the Text color list, select Inherit (the default) to inherit the text color from the setting in the Form node, or select one of the predefined colors, such as Black. Select Custom to choose a custom text color from the color palette.
From the Background color list, select a color to use as the background in the input field: White (the default), Transparent, any of the predefined basic colors, or Custom, which makes it possible to select a custom color from a color palette.
From the Text alignment list, select an alignment for the text in the input field: Left, Center, or Right.
The font and the font size for the text use the font settings from the Forms node by default. Select a font from the Font list: Default font or any of the available fonts. If needed, choose or enter a font size (in points) in the Font size combo box. The default is to use the Default size for the font.
Select the Bold check box to use a boldface font and the Italic check box to use italics (an italic font).
Under State, you can control the initial state of the input field when users run the application. By default, the input field is visible and enabled. Clear the Visible or Enabled check box if you want to make the initial state so that the input field is hidden or unavailable. You can then make it visible or enable it using a method. In the Form Editor, the state of the form object is indicated by a change in its appearance. Objects that are hidden become visible when selected in the Form Editor.
Events
You can specify a method or command sequence to run when an event such as data entry occurs. The On data change list contains None (the default) and any available methods or command sequence. You can add the following types of events by choosing from the Create Global Method menu () to the right of the On data change list:
Choose Create Global Method () to create a global method. Type the name of the global method in the Name field of the Create Global Method dialog box that opens and then click OK. The global method is then added under Methods, and its Method Editor window opens.
Choose Create Form Method () to create a form method. Type the name of the form method in the Name field of the Create Form Method dialog box that opens and then click OK. The form method is then added under the Methods node under the Form node, and its Method Editor window opens.
Choose Create Local Method () to create a local method. Its Method Editor window opens.
Choose Create Command Sequence () to create a command sequence using the Create Command Sequence dialog box that opens. There you can choose commands from the available Forms, GUI Commands, Declarations, Form Declarations, Methods, Form Methods, Libraries, and Model folders. To add a command, right-click the desired command node and choose the command to use (Run, for example). The command then appears in the list of commands below. You can edit that command sequence using the toolbar buttons for moving and deleting commands below the table. Click the Convert to Method button () and choose Convert to Method or Convert to Form Method to convert the command sequence to a method. Click the Go to Method button () below the table to select the method in the Application Builder tree and open the method in a Method Editor window. For commands that include arguments, click the Edit Argument button () to choose an argument in the Edit Argument dialog box that opens.
There can only be one local method and one command sequence so if you add one or both of them, the menu will instead contain Remove Local Method () and Remove Command Sequence (), respectively. Click one of them to delete the local method or command sequence.
The selected method in the On data change list then changes to the created method or command sequence. You can also Ctrl+Alt-click the input field object or right-click it to create a local method or (by choosing Edit Method or Edit Local Method) to open the method associated with the command. To open the selected method or command sequence, click the Go to Source button (). The focus then moves to the method’s editor window or the Command Sequence dialog box, respectively.
For events triggered by data change, the event is triggered after the new data value is stored in the data source.
If you select more than one form object and they all support the On data change event, you can specify a method to, for example, make them inform users that plots and outputs are invalid.