Skip to content

Commit

Permalink
Merge pull request #1795 from EnsembleUI/1794-required-error-message
Browse files Browse the repository at this point in the history
Added errorMessage  for required & errorStyle property for Text Form Fields
  • Loading branch information
mehsaandev authored Dec 29, 2024
2 parents 8730689 + 19014be commit fc1177a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions modules/ensemble/lib/widget/helpers/form_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class FormFieldController extends WidgetController {

bool? enabled;
bool required = false;
String? requiredMessage;
TextStyle? errorStyle;
IconModel? icon;
int? maxWidth;

Expand Down Expand Up @@ -63,6 +65,8 @@ class FormFieldController extends WidgetController {
'floatLabel': (value) =>
floatLabel = Utils.getBool(value, fallback: false),
'required': (value) => required = Utils.getBool(value, fallback: false),
'requiredMessage': (value) => requiredMessage =
Utils.getString(value, fallback: 'This field is required'),
'icon': (value) => icon = Utils.getIcon(value),
'maxWidth': (value) =>
maxWidth = Utils.optionalInt(value, min: 0, max: 5000),
Expand All @@ -83,6 +87,7 @@ class FormFieldController extends WidgetController {
'focusedErrorBorderColor': (color) =>
focusedErrorBorderColor = Utils.getColor(color),
'labelStyle': (style) => labelStyle = Utils.getTextStyle(style),
'errorStyle': (style) => errorStyle = Utils.getTextStyle(style),
'floatingLabelStyle': (style) =>
floatingLabelStyle = Utils.getTextStyle(style),
'label': (value) => label = Utils.optionalString(value),
Expand Down
9 changes: 8 additions & 1 deletion modules/ensemble/lib/widget/input/form_textfield.dart
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@ class TextInputState extends FormFieldWidgetState<BaseTextInput>
labelText: widget._controller.label,
);
}
if (widget._controller.errorStyle != null) {
decoration = decoration.copyWith(
errorStyle: widget._controller.errorStyle,
);
}

// for password, show the toggle plain text/obscure text
if ((widget.isPassword() || widget._controller.obscureText == true) &&
Expand Down Expand Up @@ -438,7 +443,9 @@ class TextInputState extends FormFieldWidgetState<BaseTextInput>
if (value == null || value.isEmpty) {
return widget._controller.required
? Utils.translateWithFallback(
'ensemble.input.required', 'This field is required')
'ensemble.input.required',
widget._controller.requiredMessage ??
'This field is required')
: null;
}

Expand Down

0 comments on commit fc1177a

Please sign in to comment.