Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added errorMessage for required & errorStyle property for Form Fields #1795

Merged
merged 2 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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