Working With Forms > The Form Objects > Input Field

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 a 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, which 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 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 Model 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 that 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, which you find under the main Model node and under each Study node, as the source:
The Expected Computation Time node () under Model>Information (): The expected computation time is a value that the application developer 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 that 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 right-click the node and choose Use as 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. 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 the 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. If the value or expression that the user enters is incompatible, the value or expression is highlighted in orange as a warning, and a tooltip displays to describe the unit mismatch. If there is a unit mismatch, the application uses the numerical value of the entered value or expression and adds the default unit as specified (for example, 9[kg] is converted to 9[m] if the expected physical quantity is a length).
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 get the same type of information and handling as in the previous case if there is a unit mismatch.
Append unit to number: Using this option, the 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. Using this option, 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 Minimum and Maximum to specify a lower and upper limit, respectively, in the corresponding text fields. The limits can be numerical values or expressions, including parameters defined in the global Parameters node’s Settings window. The limits then 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 Minimum and Maximum to specify a lower and upper limit (as integer values), respectively, in the corresponding text fields.
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 but the characters a, b, and 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.
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 a 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 input field’s absolute position 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.
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 that opens.
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 that opens.
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.
Select 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.
Events
For certain types of form objects, you can specify a method to run when an event such as data entry occurs. The On data change list contains None (the default) and any available methods. To add a local method for an event, click the Create Local Method button () to the right of the On data change list, or right-click the input field object. The selected method in the On data change list then changes to Local method. To open the local method, click the Go to Source button (). An empty onDataChange editor window then opens, in which you can define the local method. Click the Remove Local Method button () to delete the local method.
For events triggered by data change, the event is triggered after the new data value is stored in the data source.
You can also Ctrl+Alt-click on the input field:
If the On data change list is set to a method, Ctrl+Alt-click opens the method’s editor window.
If the On data change list is set to None, Ctrl+Alt-click creates a local method if needed, sets the list to Local method, and opens the local method’s editor window.
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 all of them inform users that plots and outputs are invalid.