add validation in faq and discount page
This commit is contained in:
@@ -30,6 +30,7 @@ class _DiscountEditorState extends State<DiscountEditor> {
|
||||
bool _isNew = false;
|
||||
String customerName = '';
|
||||
String customerId = '';
|
||||
final _discountFormKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -51,12 +52,28 @@ class _DiscountEditorState extends State<DiscountEditor> {
|
||||
final codeBox = InputText(
|
||||
labelTextKey: 'discount.code',
|
||||
iconData: FontAwesomeIcons.algolia,
|
||||
controller: _codeController);
|
||||
controller: _codeController,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Please insert code";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
final amountBox = InputText(
|
||||
labelTextKey: 'discount.amount',
|
||||
iconData: FontAwesomeIcons.moneyBill,
|
||||
controller: _amountController);
|
||||
controller: _amountController,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Please insert amount";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
final statusBox = DisplayText(
|
||||
text: _statusController.text,
|
||||
@@ -100,7 +117,9 @@ class _DiscountEditorState extends State<DiscountEditor> {
|
||||
onPressed: _delete)
|
||||
],
|
||||
),
|
||||
body: Padding(
|
||||
body: Form(
|
||||
key: _discountFormKey,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
@@ -128,11 +147,15 @@ class _DiscountEditorState extends State<DiscountEditor> {
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
_save() async {
|
||||
if (!_discountFormKey.currentState!.validate()) {
|
||||
return null;
|
||||
}
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
|
||||
@@ -29,7 +29,7 @@ class _FAQEditorState extends State<FAQEditor> {
|
||||
TextEditingController _pageLabelEng = new TextEditingController();
|
||||
TextEditingController _pageLabelMm = new TextEditingController();
|
||||
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _faqFormKey = GlobalKey<FormState>();
|
||||
bool _isLoading = false;
|
||||
bool _isNew = false;
|
||||
String _pageLink = info;
|
||||
@@ -57,9 +57,16 @@ class _FAQEditorState extends State<FAQEditor> {
|
||||
final snBox = InputText(
|
||||
controller: _sn,
|
||||
labelTextKey: "faq.edit.sn",
|
||||
maxLines: 1,
|
||||
withBorder: false,
|
||||
textInputType: TextInputType.number,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty || value.length==0) {
|
||||
return "Please insert S/N";
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
final questionEngBox = InputText(
|
||||
@@ -151,7 +158,7 @@ class _FAQEditorState extends State<FAQEditor> {
|
||||
],
|
||||
),
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
key: _faqFormKey,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(left: 24.0, right: 24.0),
|
||||
child: ListView(
|
||||
@@ -189,6 +196,10 @@ class _FAQEditorState extends State<FAQEditor> {
|
||||
}
|
||||
|
||||
_save() async {
|
||||
if (!_faqFormKey.currentState!.validate()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
@@ -212,7 +223,7 @@ class _FAQEditorState extends State<FAQEditor> {
|
||||
}
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
showMsgDialog(context, "Error", "Invalid S/N");
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
|
||||
Reference in New Issue
Block a user