Skip to content

Commit

Permalink
added requiredMessage and errorStyle for form fields
Browse files Browse the repository at this point in the history
  • Loading branch information
mehsaandev committed Feb 3, 2025
1 parent 86161f9 commit 8e89bdb
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 10 deletions.
6 changes: 4 additions & 2 deletions modules/ensemble/lib/widget/checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class CheckboxState extends FormFieldWidgetState<EnsembleCheckbox> {
validator: (value) {
if (widget._controller.required && !widget._controller.value) {
return Utils.translateWithFallback(
'ensemble.input.required', 'This field is required');
'ensemble.input.required', widget._controller.requiredMessage ?? 'This field is required');
}
return null;
},
Expand All @@ -138,7 +138,9 @@ class CheckboxState extends FormFieldWidgetState<EnsembleCheckbox> {
enabledBorder: InputBorder.none,
disabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
errorText: field.errorText),
errorText: field.errorText,
errorStyle: widget._controller.errorStyle ?? Theme.of(context).inputDecorationTheme.errorStyle,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
Expand Down
4 changes: 3 additions & 1 deletion modules/ensemble/lib/widget/input/dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class SelectOneState extends FormFieldWidgetState<SelectOne>
validator: (value) {
if (widget._controller.required && widget.getValue() == null) {
return Utils.translateWithFallback(
'ensemble.input.required', 'This field is required');
'ensemble.input.required', widget._controller.requiredMessage ?? 'This field is required');
}
return null;
},
Expand Down Expand Up @@ -409,6 +409,7 @@ class SelectOneState extends FormFieldWidgetState<SelectOne>
)),
decoration: inputDecoration.copyWith(
contentPadding: adjustedContentPadding,
errorStyle: widget._controller.errorStyle ?? Theme.of(context).inputDecorationTheme.errorStyle,
labelText: widget.controller.floatLabel == true
? widget.controller.label
: null,
Expand Down Expand Up @@ -449,6 +450,7 @@ class SelectOneState extends FormFieldWidgetState<SelectOne>
.fillColor, // Background color for the field
enabledBorder: getEnabledBorder(),
focusedBorder: getSafeFocusedBorder(),
errorStyle: widget._controller.errorStyle ?? Theme.of(context).inputDecorationTheme.errorStyle
),
onChanged: (value) {
// Preserve the cursor position
Expand Down
3 changes: 2 additions & 1 deletion modules/ensemble/lib/widget/input/form_date.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class DateState extends FormFieldWidgetState<Date> {
if (widget._controller.required &&
widget._controller.value == null) {
return Utils.translateWithFallback(
'ensemble.input.required', 'This field is required');
'ensemble.input.required', widget._controller.requiredMessage ?? 'This field is required');
}
return null;
},
Expand All @@ -105,6 +105,7 @@ class DateState extends FormFieldWidgetState<Date> {
isEmpty: widget._controller.value == null,
decoration: inputDecoration.copyWith(
errorText: field.errorText,
errorStyle: widget._controller.errorStyle ?? Theme.of(context).inputDecorationTheme.errorStyle,
hintText: widget._controller.placeholder ??
widget._controller.hintText ??
Utils.translateWithFallback(
Expand Down
3 changes: 2 additions & 1 deletion modules/ensemble/lib/widget/input/form_time.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class TimeState extends FormFieldWidgetState<Time> {
validator: (value) {
if (widget._controller.required && widget._controller.value == null) {
return Utils.translateWithFallback(
'ensemble.input.required', 'This field is required');
'ensemble.input.required', widget._controller.requiredMessage ?? 'This field is required');
}
return null;
},
Expand All @@ -218,6 +218,7 @@ class TimeState extends FormFieldWidgetState<Time> {
disabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
errorText: field.errorText,
errorStyle: widget._controller.errorStyle ?? Theme.of(context).inputDecorationTheme.errorStyle,
),
child: Row(
mainAxisSize: MainAxisSize.min,
Expand Down
3 changes: 2 additions & 1 deletion modules/ensemble/lib/widget/radio/radio_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class RadioState extends FormFieldWidgetState<RadioButton> {
if (widget.controller.required &&
radioButtonController.selectedValue == null) {
return Utils.translateWithFallback(
'ensemble.input.required', 'This field is required');
'ensemble.input.required', widget._controller.requiredMessage ?? 'This field is required');
}
return null;
},
Expand All @@ -100,6 +100,7 @@ class RadioState extends FormFieldWidgetState<RadioButton> {
disabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
errorText: field.errorText,
errorStyle: widget._controller.errorStyle ?? Theme.of(context).inputDecorationTheme.errorStyle,
),
child: ChangeNotifierProvider(
create: (context) => radioButtonController,
Expand Down
5 changes: 3 additions & 2 deletions modules/ensemble/lib/widget/radio/radio_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class RadioGroupState extends FormFieldWidgetState<RadioGroup>
if (widget._controller.required &&
widget._controller.selectedValue == null) {
return Utils.translateWithFallback(
'ensemble.input.required', 'This field is required');
'ensemble.input.required', widget._controller.requiredMessage ?? 'This field is required');
}
return null;
},
Expand All @@ -167,7 +167,8 @@ class RadioGroupState extends FormFieldWidgetState<RadioGroup>
enabledBorder: InputBorder.none,
disabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
errorText: field.errorText),
errorText: field.errorText,
errorStyle: widget._controller.errorStyle ?? Theme.of(context).inputDecorationTheme.errorStyle),
child: rtn);
},
),
Expand Down
5 changes: 3 additions & 2 deletions modules/ensemble/lib/widget/switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class SwitchBaseState extends FormFieldWidgetState<SwitchBase> {

if (switchRequiredStatus || tripleStateRequiredStatus) {
return Utils.translateWithFallback(
'ensemble.input.required', 'This field is required');
'ensemble.input.required', widget._controller.requiredMessage ?? 'This field is required');
}
return null;
},
Expand All @@ -143,7 +143,8 @@ class SwitchBaseState extends FormFieldWidgetState<SwitchBase> {
enabledBorder: InputBorder.none,
disabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
errorText: field.errorText),
errorText: field.errorText,
errorStyle: widget._controller.errorStyle ?? Theme.of(context).inputDecorationTheme.errorStyle),
child: Row(
mainAxisAlignment: MainAxisAlignment.start, children: children),
);
Expand Down

0 comments on commit 8e89bdb

Please sign in to comment.