add validation in faq and discount page
This commit is contained in:
@@ -30,6 +30,7 @@ class _DiscountEditorState extends State<DiscountEditor> {
|
|||||||
bool _isNew = false;
|
bool _isNew = false;
|
||||||
String customerName = '';
|
String customerName = '';
|
||||||
String customerId = '';
|
String customerId = '';
|
||||||
|
final _discountFormKey = GlobalKey<FormState>();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -49,14 +50,30 @@ class _DiscountEditorState extends State<DiscountEditor> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final codeBox = InputText(
|
final codeBox = InputText(
|
||||||
labelTextKey: 'discount.code',
|
labelTextKey: 'discount.code',
|
||||||
iconData: FontAwesomeIcons.algolia,
|
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(
|
final amountBox = InputText(
|
||||||
labelTextKey: 'discount.amount',
|
labelTextKey: 'discount.amount',
|
||||||
iconData: FontAwesomeIcons.moneyBill,
|
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(
|
final statusBox = DisplayText(
|
||||||
text: _statusController.text,
|
text: _statusController.text,
|
||||||
@@ -100,39 +117,45 @@ class _DiscountEditorState extends State<DiscountEditor> {
|
|||||||
onPressed: _delete)
|
onPressed: _delete)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: Padding(
|
body: Form(
|
||||||
padding: const EdgeInsets.all(8.0),
|
key: _discountFormKey,
|
||||||
child: Column(
|
child: Padding(
|
||||||
children: <Widget>[
|
padding: const EdgeInsets.all(8.0),
|
||||||
Expanded(
|
child: Column(
|
||||||
child: ListView(
|
children: <Widget>[
|
||||||
children: <Widget>[
|
Expanded(
|
||||||
codeBox,
|
child: ListView(
|
||||||
amountBox,
|
children: <Widget>[
|
||||||
SizedBox(height: 7),
|
codeBox,
|
||||||
customerBox,
|
amountBox,
|
||||||
SizedBox(height: 7),
|
SizedBox(height: 7),
|
||||||
widget.discount == null
|
customerBox,
|
||||||
? Container()
|
SizedBox(height: 7),
|
||||||
: Container(
|
widget.discount == null
|
||||||
padding: EdgeInsets.only(top: 5),
|
? Container()
|
||||||
child: statusBox,
|
: Container(
|
||||||
),
|
padding: EdgeInsets.only(top: 5),
|
||||||
],
|
child: statusBox,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
fcsButton(context, getLocalString(context, "btn.save"),
|
||||||
fcsButton(context, getLocalString(context, "btn.save"),
|
callack: _save),
|
||||||
callack: _save),
|
SizedBox(
|
||||||
SizedBox(
|
height: 30,
|
||||||
height: 30,
|
)
|
||||||
)
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
_save() async {
|
_save() async {
|
||||||
|
if (!_discountFormKey.currentState!.validate()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
setState(() {
|
setState(() {
|
||||||
_isLoading = true;
|
_isLoading = true;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class _FAQEditorState extends State<FAQEditor> {
|
|||||||
TextEditingController _pageLabelEng = new TextEditingController();
|
TextEditingController _pageLabelEng = new TextEditingController();
|
||||||
TextEditingController _pageLabelMm = new TextEditingController();
|
TextEditingController _pageLabelMm = new TextEditingController();
|
||||||
|
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _faqFormKey = GlobalKey<FormState>();
|
||||||
bool _isLoading = false;
|
bool _isLoading = false;
|
||||||
bool _isNew = false;
|
bool _isNew = false;
|
||||||
String _pageLink = info;
|
String _pageLink = info;
|
||||||
@@ -57,9 +57,16 @@ class _FAQEditorState extends State<FAQEditor> {
|
|||||||
final snBox = InputText(
|
final snBox = InputText(
|
||||||
controller: _sn,
|
controller: _sn,
|
||||||
labelTextKey: "faq.edit.sn",
|
labelTextKey: "faq.edit.sn",
|
||||||
maxLines: 1,
|
|
||||||
withBorder: false,
|
withBorder: false,
|
||||||
textInputType: TextInputType.number,
|
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(
|
final questionEngBox = InputText(
|
||||||
@@ -151,7 +158,7 @@ class _FAQEditorState extends State<FAQEditor> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: Form(
|
body: Form(
|
||||||
key: _formKey,
|
key: _faqFormKey,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.only(left: 24.0, right: 24.0),
|
padding: EdgeInsets.only(left: 24.0, right: 24.0),
|
||||||
child: ListView(
|
child: ListView(
|
||||||
@@ -189,6 +196,10 @@ class _FAQEditorState extends State<FAQEditor> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_save() async {
|
_save() async {
|
||||||
|
if (!_faqFormKey.currentState!.validate()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_isLoading = true;
|
_isLoading = true;
|
||||||
});
|
});
|
||||||
@@ -212,7 +223,7 @@ class _FAQEditorState extends State<FAQEditor> {
|
|||||||
}
|
}
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
showMsgDialog(context, "Error", e.toString());
|
showMsgDialog(context, "Error", "Invalid S/N");
|
||||||
} finally {
|
} finally {
|
||||||
setState(() {
|
setState(() {
|
||||||
_isLoading = false;
|
_isLoading = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user