Form
Reactive Form Component with Advanced Validation
Selector
smart-form
Properties
- append:string - HTML Content displayed after the Form Control
- controlOptions:any - JSON object with initialization properties of the UI component. Example: { dataSource: ['item 1', 'item 2', 'item 3'] } will set the dataSource property of the Form control.
- controlType:string - The type of the control.
- columns:number - Sets the Form Group columns.
- columnSpan:number - Sets the Form control column span.
- controls:[] Property object's options:
- append:string - HTML Content displayed after the Form Control
- controlOptions:any - JSON object with initialization properties of the UI component. Example: { dataSource: ['item 1', 'item 2', 'item 3'] } will set the dataSource property of the Form control.
- controlType:string - The type of the control.
- columns:number - Sets the Form Group columns.
- columnSpan:number - Sets the Form control column span.
- dataField:string - Sets the Form control data field. The control's inner input's name is set to the dataField value and in the FormGroup it is accessible through the dataField value.
- disabled:boolean - Sets the Form control disabled mode.
- dirty:boolean - Gets whether the Form control is 'dirty' i.e its value is changed by the user.
- info:string - Gets or Sets the Form control's info icon's tooltip.
- invalid:boolean - Gets whether the Form control is invalid.
- label:string - Gets or Sets the Form control's label.
- labelPosition:string - Gets or Sets the Form control's label position.
- labelOffset:number - Gets or Sets the offset between the label and the control.
- labelAlign:string - FormGroup only(when controlType is set to 'group'). Gets or Sets whether the navigation buttons are displayed. The property has effect when the viewMode property is set.
- nextButtonLabel:string - FormGroup only(when controlType is set to 'group'). Gets or Sets the next button label.
- backButtonLabel:string - FormGroup only(when controlType is set to 'group'). Gets or Sets the back button label.
- prepend:string - HTML Content displayed before the Form Control
- readonly:boolean - Gets or Sets the Form control readonly mode.
- untouched:boolean - Gets whether the Form control is not touched by the user. This flag is changed usually on blur, after the user interacted with the Form control
- placeholder:string - Gets or Sets the placeholder.
- showButtons:boolean - FormGroup only(when controlType is set to 'group'). Gets or Sets whether the navigation buttons are displayed. The property has effect when the viewMode property is set.
- value:any - Sets or Gets the Form control or Form group value.
- valid:boolean - Gets whether the Form control is valid.
- validationRules:[] | null - Sets or gets the column's validation rules. The expected value is an Array of Objects. Each object should have a 'type' property that can be set to 'required', 'min', 'max', 'minLength', 'maxLength', 'email', 'null', 'requiredTrue', 'minData', 'maxDate', 'pattern'. The 'value' property should be set, too. For validation rule types 'required', 'requiredTrue' and 'null' you can skip the 'value' property. Optional property is 'message', which determines the error message.
- viewMode:string - FormGroup only(when controlType is set to 'group'). Gets or Sets the form'group view mode.
- dataField:string - Sets the Form control data field. The control's inner input's name is set to the dataField value and in the FormGroup it is accessible through the dataField value.
- disabled:boolean - Sets the Form control disabled mode.
- dirty:boolean - Gets whether the Form control is 'dirty' i.e its value is changed by the user.
- info:string - Gets or Sets the Form control's info icon's tooltip.
- invalid:boolean - Gets whether the Form control is invalid.
- label:string - Gets or Sets the Form control's label.
- labelPosition:string - Gets or Sets the Form control's label position.
- labelOffset:number - Gets or Sets the offset between the label and the control.
- labelAlign:string - FormGroup only(when controlType is set to 'group'). Gets or Sets whether the navigation buttons are displayed. The property has effect when the viewMode property is set.
- nextButtonLabel:string - FormGroup only(when controlType is set to 'group'). Gets or Sets the next button label.
- backButtonLabel:string - FormGroup only(when controlType is set to 'group'). Gets or Sets the back button label.
- prepend:string - HTML Content displayed before the Form Control
- readonly:boolean - Gets or Sets the Form control readonly mode.
- untouched:boolean - Gets whether the Form control is not touched by the user. This flag is changed usually on blur, after the user interacted with the Form control
- placeholder:string - Gets or Sets the placeholder.
- showButtons:boolean - FormGroup only(when controlType is set to 'group'). Gets or Sets whether the navigation buttons are displayed. The property has effect when the viewMode property is set.
- value:any - Sets or Gets the Form control or Form group value.
- valid:boolean - Gets whether the Form control is valid.
- validationRules:[] | null - Sets or gets the column's validation rules. The expected value is an Array of Objects. Each object should have a 'type' property that can be set to 'required', 'min', 'max', 'minLength', 'maxLength', 'email', 'null', 'requiredTrue', 'minData', 'maxDate', 'pattern'. The 'value' property should be set, too. For validation rule types 'required', 'requiredTrue' and 'null' you can skip the 'value' property. Optional property is 'message', which determines the error message. Property object's options:
- viewMode:string - FormGroup only(when controlType is set to 'group'). Gets or Sets the form'group view mode.
status
object contains the following boolean properties: dirty
(indicates if the form field has been modified), untouched
(indicates if the field has not been focused by the user), and disabled
(indicates if the field is currently disabled).Methods
Properties
columnsnumber
Defines or retrieves the number of columns used to arrange form fields, determining how fields are organized and displayed within the form layout.
Default value
1controls[]
Gets or sets the collection of form controls associated with the form. This allows you to retrieve the current controls or update them with a new set of controls.
Properties
appendstring
HTML Content displayed after the Form Control
Default value
""Get the append property.
const form = document.querySelector('smart-form');
let append = form.controls["firstName"].append;
controlOptionsany
JSON object with initialization properties of the UI component. Example: { dataSource: ['item 1', 'item 2', 'item 3'] } will set the dataSource property of the Form control.
Get the controlOptions property.
const form = document.querySelector('smart-form');
let controlOptions = form.controls["firstName"].controlOptions;
controlType"button" | "boolean" | "comboBox" | "checkInput" | "datetime" | "dropDownList" | "group" | "input" | "label" | "multiInput" | "multiComboInput" | "mask" | "number" | "password" | "radioButton" | "submit" | "textarea" | "template"
The type of the control.
Allowed Values
- "button" - Button control
- "boolean" - Checkbox control.
- "comboBox" - ComboBox control.
- "checkInput" - Check input control.
- "datetime" - Date/Time input control.
- "dropDownList" - dropDownList control.
- "group" - Sets the control type to FormGroup.
- "input" - Text input control.
- "label" - Label control.
- "multiInput" - Multi input control.
- "multiComboInput" - Multi combo input control.
- "mask" - Masked text input. The mask property is expected to be set to a string.
- "number" - Numeric text input control.
- "password" - Password text input contorl.
- "radioButton" - Radio Button control. When setting this option, the options property defines the Array of radio buttons. The optionsLayout property which accepts 'horizontal' and 'vertical' values defines the layout of the radio buttons.
- "submit" - Submit button, which submits the Form.
- "textarea" - Text area control.
- "template" - Template control. The template property should be set to any HTML string.
Default value
"input"Get the controlType property.
const form = document.querySelector('smart-form');
let controlType = form.controls["firstName"].controlType;
columnsnumber
Sets the Form Group columns.
Default value
1Get the columns property.
const form = document.querySelector('smart-form');
let columns = form.controls["firstName"].columns;
columnSpannumber
Sets the Form control column span.
Default value
1Get the columnSpan property.
const form = document.querySelector('smart-form');
let columnSpan = form.controls["firstName"].columnSpan;
controls[]
Properties
appendstring
HTML Content displayed after the Form Control
Default value
""Get the append property.
const form = document.querySelector('smart-form');
let append = form.controls["firstName"].controls["firstName"].append;
controlOptionsany
JSON object with initialization properties of the UI component. Example: { dataSource: ['item 1', 'item 2', 'item 3'] } will set the dataSource property of the Form control.
Get the controlOptions property.
const form = document.querySelector('smart-form');
let controlOptions = form.controls["firstName"].controls["firstName"].controlOptions;
controlType"button" | "boolean" | "comboBox" | "checkInput" | "datetime" | "dropDownList" | "group" | "input" | "label" | "multiInput" | "multiComboInput" | "mask" | "number" | "password" | "radioButton" | "submit" | "textarea" | "template"
The type of the control.
Allowed Values
- "button" - Button control
- "boolean" - Checkbox control.
- "comboBox" - ComboBox control.
- "checkInput" - Check input control.
- "datetime" - Date/Time input control.
- "dropDownList" - dropDownList control.
- "group" - Sets the control type to FormGroup.
- "input" - Text input control.
- "label" - Label control.
- "multiInput" - Multi input control.
- "multiComboInput" - Multi combo input control.
- "mask" - Masked text input. The mask property is expected to be set to a string.
- "number" - Numeric text input control.
- "password" - Password text input contorl.
- "radioButton" - Radio Button control. When setting this option, the options property defines the Array of radio buttons. The optionsLayout property which accepts 'horizontal' and 'vertical' values defines the layout of the radio buttons.
- "submit" - Submit button, which submits the Form.
- "textarea" - Text area control.
- "template" - Template control. The template property should be set to any HTML string.
Default value
"input"Get the controlType property.
const form = document.querySelector('smart-form');
let controlType = form.controls["firstName"].controls["firstName"].controlType;
columnsnumber
Sets the Form Group columns.
Default value
1Get the columns property.
const form = document.querySelector('smart-form');
let columns = form.controls["firstName"].controls["firstName"].columns;
columnSpannumber
Sets the Form control column span.
Default value
1Get the columnSpan property.
const form = document.querySelector('smart-form');
let columnSpan = form.controls["firstName"].controls["firstName"].columnSpan;
dataFieldstring
Sets the Form control data field. The control's inner input's name is set to the dataField value and in the FormGroup it is accessible through the dataField value.
Default value
""Get the dataField property.
const form = document.querySelector('smart-form');
let dataField = form.controls["firstName"].controls["firstName"].dataField;
disabledboolean
Sets the Form control disabled mode.
Default value
falseGet the disabled property.
const form = document.querySelector('smart-form');
let disabled = form.controls["firstName"].controls["firstName"].disabled;
dirtyboolean
Gets whether the Form control is 'dirty' i.e its value is changed by the user.
Default value
falseGet the dirty property.
const form = document.querySelector('smart-form');
let dirty = form.controls["firstName"].controls["firstName"].dirty;
infostring
Gets or Sets the Form control's info icon's tooltip.
Default value
""Get the info property.
const form = document.querySelector('smart-form');
let info = form.controls["firstName"].controls["firstName"].info;
invalidboolean
Gets whether the Form control is invalid.
Default value
falseGet the invalid property.
const form = document.querySelector('smart-form');
let invalid = form.controls["firstName"].controls["firstName"].invalid;
labelstring
Gets or Sets the Form control's label.
Default value
""Get the label property.
const form = document.querySelector('smart-form');
let label = form.controls["firstName"].controls["firstName"].label;
labelPosition"left" | "top"
Gets or Sets the Form control's label position.
Default value
"left"Get the labelPosition property.
const form = document.querySelector('smart-form');
let labelPosition = form.controls["firstName"].controls["firstName"].labelPosition;
labelOffsetnumber
Gets or Sets the offset between the label and the control.
Default value
10Get the labelOffset property.
const form = document.querySelector('smart-form');
let labelOffset = form.controls["firstName"].controls["firstName"].labelOffset;
labelAlignstring
FormGroup only(when controlType is set to 'group'). Gets or Sets whether the navigation buttons are displayed. The property has effect when the viewMode property is set.
Default value
"left"Get the labelAlign property.
const form = document.querySelector('smart-form');
let labelAlign = form.controls["firstName"].controls["firstName"].labelAlign;
nextButtonLabelstring
FormGroup only(when controlType is set to 'group'). Gets or Sets the next button label.
Default value
"Next"Get the nextButtonLabel property.
const form = document.querySelector('smart-form');
let nextButtonLabel = form.controls["firstName"].controls["firstName"].nextButtonLabel;
backButtonLabelstring
FormGroup only(when controlType is set to 'group'). Gets or Sets the back button label.
Default value
"Back"Get the backButtonLabel property.
const form = document.querySelector('smart-form');
let backButtonLabel = form.controls["firstName"].controls["firstName"].backButtonLabel;
prependstring
HTML Content displayed before the Form Control
Default value
""Get the prepend property.
const form = document.querySelector('smart-form');
let prepend = form.controls["firstName"].controls["firstName"].prepend;
readonlyboolean
Gets or Sets the Form control readonly mode.
Default value
falseGet the readonly property.
const form = document.querySelector('smart-form');
let readonly = form.controls["firstName"].controls["firstName"].readonly;
untouchedboolean
Gets whether the Form control is not touched by the user. This flag is changed usually on blur, after the user interacted with the Form control
Default value
falseGet the untouched property.
const form = document.querySelector('smart-form');
let untouched = form.controls["firstName"].controls["firstName"].untouched;
placeholderstring
Gets or Sets the placeholder.
Default value
""Get the placeholder property.
const form = document.querySelector('smart-form');
let placeholder = form.controls["firstName"].controls["firstName"].placeholder;
showButtonsboolean
FormGroup only(when controlType is set to 'group'). Gets or Sets whether the navigation buttons are displayed. The property has effect when the viewMode property is set.
Default value
falseGet the showButtons property.
const form = document.querySelector('smart-form');
let showButtons = form.controls["firstName"].controls["firstName"].showButtons;
valueany
Sets or Gets the Form control or Form group value.
Get the value property.
const form = document.querySelector('smart-form');
let value = form.controls["firstName"].controls["firstName"].value;
validboolean
Gets whether the Form control is valid.
Default value
falseGet the valid property.
const form = document.querySelector('smart-form');
let valid = form.controls["firstName"].controls["firstName"].valid;
validationRules[] | null
Sets or gets the column's validation rules. The expected value is an Array of Objects. Each object should have a 'type' property that can be set to 'required', 'min', 'max', 'minLength', 'maxLength', 'email', 'null', 'requiredTrue', 'minData', 'maxDate', 'pattern'. The 'value' property should be set, too. For validation rule types 'required', 'requiredTrue' and 'null' you can skip the 'value' property. Optional property is 'message', which determines the error message.
Example
Set the validationRules property by using the HTML Element's instance.
const form = document.querySelector('smart-form');
form.controls["firstName"].controls["firstName"].validationRules = {type: 'email'};
Get the validationRules property.
const form = document.querySelector('smart-form');
let validationRules = form.controls["firstName"].controls["firstName"].validationRules;
viewMode"" | "accordion" | "tabs" | "breadcrumb"
FormGroup only(when controlType is set to 'group'). Gets or Sets the form'group view mode.
Default value
""Get the viewMode property.
const form = document.querySelector('smart-form');
let viewMode = form.controls["firstName"].controls["firstName"].viewMode;
Get the controls property.
const form = document.querySelector('smart-form');
let controls = form.controls["firstName"].controls;
dataFieldstring
Sets the Form control data field. The control's inner input's name is set to the dataField value and in the FormGroup it is accessible through the dataField value.
Default value
""Get the dataField property.
const form = document.querySelector('smart-form');
let dataField = form.controls["firstName"].dataField;
disabledboolean
Sets the Form control disabled mode.
Default value
falseGet the disabled property.
const form = document.querySelector('smart-form');
let disabled = form.controls["firstName"].disabled;
dirtyboolean
Gets whether the Form control is 'dirty' i.e its value is changed by the user.
Default value
falseGet the dirty property.
const form = document.querySelector('smart-form');
let dirty = form.controls["firstName"].dirty;
infostring
Gets or Sets the Form control's info icon's tooltip.
Default value
""Get the info property.
const form = document.querySelector('smart-form');
let info = form.controls["firstName"].info;
invalidboolean
Gets whether the Form control is invalid.
Default value
falseGet the invalid property.
const form = document.querySelector('smart-form');
let invalid = form.controls["firstName"].invalid;
labelstring
Gets or Sets the Form control's label.
Default value
""Get the label property.
const form = document.querySelector('smart-form');
let label = form.controls["firstName"].label;
labelPosition"left" | "top"
Gets or Sets the Form control's label position.
Default value
"left"Get the labelPosition property.
const form = document.querySelector('smart-form');
let labelPosition = form.controls["firstName"].labelPosition;
labelOffsetnumber
Gets or Sets the offset between the label and the control.
Default value
10Get the labelOffset property.
const form = document.querySelector('smart-form');
let labelOffset = form.controls["firstName"].labelOffset;
labelAlignstring
FormGroup only(when controlType is set to 'group'). Gets or Sets whether the navigation buttons are displayed. The property has effect when the viewMode property is set.
Default value
"left"Get the labelAlign property.
const form = document.querySelector('smart-form');
let labelAlign = form.controls["firstName"].labelAlign;
nextButtonLabelstring
FormGroup only(when controlType is set to 'group'). Gets or Sets the next button label.
Default value
"Next"Get the nextButtonLabel property.
const form = document.querySelector('smart-form');
let nextButtonLabel = form.controls["firstName"].nextButtonLabel;
backButtonLabelstring
FormGroup only(when controlType is set to 'group'). Gets or Sets the back button label.
Default value
"Back"Get the backButtonLabel property.
const form = document.querySelector('smart-form');
let backButtonLabel = form.controls["firstName"].backButtonLabel;
prependstring
HTML Content displayed before the Form Control
Default value
""Get the prepend property.
const form = document.querySelector('smart-form');
let prepend = form.controls["firstName"].prepend;
readonlyboolean
Gets or Sets the Form control readonly mode.
Default value
falseGet the readonly property.
const form = document.querySelector('smart-form');
let readonly = form.controls["firstName"].readonly;
untouchedboolean
Gets whether the Form control is not touched by the user. This flag is changed usually on blur, after the user interacted with the Form control
Default value
falseGet the untouched property.
const form = document.querySelector('smart-form');
let untouched = form.controls["firstName"].untouched;
placeholderstring
Gets or Sets the placeholder.
Default value
""Get the placeholder property.
const form = document.querySelector('smart-form');
let placeholder = form.controls["firstName"].placeholder;
showButtonsboolean
FormGroup only(when controlType is set to 'group'). Gets or Sets whether the navigation buttons are displayed. The property has effect when the viewMode property is set.
Default value
falseGet the showButtons property.
const form = document.querySelector('smart-form');
let showButtons = form.controls["firstName"].showButtons;
valueany
Sets or Gets the Form control or Form group value.
Get the value property.
const form = document.querySelector('smart-form');
let value = form.controls["firstName"].value;
validboolean
Gets whether the Form control is valid.
Default value
falseGet the valid property.
const form = document.querySelector('smart-form');
let valid = form.controls["firstName"].valid;
validationRules[] | null
Sets or gets the column's validation rules. The expected value is an Array of Objects. Each object should have a 'type' property that can be set to 'required', 'min', 'max', 'minLength', 'maxLength', 'email', 'null', 'requiredTrue', 'minData', 'maxDate', 'pattern'. The 'value' property should be set, too. For validation rule types 'required', 'requiredTrue' and 'null' you can skip the 'value' property. Optional property is 'message', which determines the error message.
Example
Set the validationRules property by using the HTML Element's instance.
const form = document.querySelector('smart-form');
form.controls["firstName"].validationRules = {type: 'email'};
Get the validationRules property.
const form = document.querySelector('smart-form');
let validationRules = form.controls["firstName"].validationRules;
viewMode"" | "accordion" | "tabs" | "breadcrumb"
FormGroup only(when controlType is set to 'group'). Gets or Sets the form'group view mode.
Default value
""Get the viewMode property.
const form = document.querySelector('smart-form');
let viewMode = form.controls["firstName"].viewMode;
Example
Set the controls property.
<smart-form controls=''></smart-form>
Set the controls property by using the HTML Element's instance.
const form = document.querySelector('smart-form');
form.controls = ;
Get the controls property.
const form = document.querySelector('smart-form');
let controls = form.controls;
onStatusChanges{(value: string): void}
Callback function invoked when the status changes. The status parameter passed to the function reflects the new state of the process, and can be one of the following string values: 'disabled', 'invalid', 'pending', or 'valid'. Use this callback to handle logic based on each specific status transition.
onValueChanges{(value: any): void}
Callback function invoked when the form's value changes. Receives the updated form data as a JSON object argument, allowing you to handle or process the new values within your application.
labelPosition"left" | "top"
Defines or retrieves the position of the labels relative to their associated elements. Specify this property to control where labels are displayed (e.g., above, below, left, or right of the element).
Default value
"left"readonlyboolean
Sets all form fields to read-only mode, preventing users from modifying their input while still allowing them to view the existing data.
Default value
false<smart-form readonly></smart-form>
showColonAfterLabelboolean
Controls the visibility of the colon character that appears after label text. When enabled, a colon is displayed after each label; when disabled, the colon is omitted.
Default value
false<smart-form show-colon-after-label></smart-form>
showSummaryboolean
Toggles the visibility of the validation summary, allowing users to display or hide a list of validation errors based on form input.
Default value
true<smart-form show-summary></smart-form>
statusany
Retrieves the current status of the Form. Each entry within the status
object contains the following boolean properties: dirty
(indicates if the form field has been modified), untouched
(indicates if the field has not been focused by the user), and disabled
(indicates if the field is currently disabled).
valueany
Retrieves or assigns the current value of the form. Use this property to access the form's data for processing or to update the form with new values programmatically.
validateOnLoadboolean
Automatically triggers form validation immediately upon form initialization, ensuring that all form fields are checked for correctness as soon as the form is rendered or instantiated.
Default value
false<smart-form validate-on-load></smart-form>
Methods
addControl( controlOptions: any): void
Inserts a new control element, such as an input field, button, or checkbox, into the Form, allowing users to interact with and submit data.
Arguments
controlOptionsany
Control options. The control options description is available in the controls property.
Invoke the addControl method.
const form = document.querySelector('smart-form'); form.addControl({"dataField":"firstName","controlType":"input"});
getControl( dataField: string): Control
Retrieves a specific control element from the form using its name attribute, as defined by the dataField parameter. This method enables direct access to the control's properties and methods for further manipulation or data retrieval.
Arguments
dataFieldstring
dataField of a FormControl or FormGroup
ReturnsControl
Invoke the getControl method.
const form = document.querySelector('smart-form'); const result = form.getControl("firstName");
insertControl( index: number, controlOptions: any): void
Adds a new control element to the Form, allowing users to dynamically extend the form’s functionality. This method enables the inclusion of input fields, buttons, dropdowns, or other interactive components within the Form, ensuring seamless integration and consistent behavior with existing controls.
Arguments
indexnumber
Control insert index
controlOptionsany
Control options. The control options description is available in the controls property.
Invoke the insertControl method.
const form = document.querySelector('smart-form'); form.insertControl(1,{"dataField":"firstName","controlType":"input"});
removeControl( controlOptions: any): void
Removes a specified control element from the Form, ensuring it is no longer rendered or managed as part of the Form's structure and behavior.
Arguments
controlOptionsany
Control options. The control options description is available in the controls property.
Invoke the removeControl method.
const form = document.querySelector('smart-form'); form.removeControl("firstName");
submit( submitOptions?: any): void
Triggers the submission of the form, sending the user-entered data to the specified server endpoint for processing. This action may also initiate form validation and execute any associated event handlers before transmitting the data.
Arguments
submitOptions?any
Sets the submit options object. The object may have the following properties: async, action, target, method. async determines whether the form will be submitted asynchronously. action determines the submit url, method sets whether the submit is through 'GET' or 'POST'. target determines the submit target.
Invoke the submit method.
const form = document.querySelector('smart-form'); form.submit();
reset(): void
Resets all fields in the form to their initial, default values, effectively clearing any user input or changes made.
Invoke the reset method.
const form = document.querySelector('smart-form'); form.reset();
validate(): void
Performs comprehensive validation of the form fields, ensuring that all required inputs are provided, data types and formats are correct, and any specified constraints or validation rules are met before allowing form submission.
Invoke the validate method.
const form = document.querySelector('smart-form'); form.validate();