Commit 26b9540e authored by Ilham Maulana's avatar Ilham Maulana 💻

fix: adding validator to loan book form

parent bc0e46c6
...@@ -47,6 +47,15 @@ class _LoanBookForm extends State<LoanBookForm> { ...@@ -47,6 +47,15 @@ class _LoanBookForm extends State<LoanBookForm> {
), ),
keyboardType: TextInputType.number, keyboardType: TextInputType.number,
inputFormatters: [FilteringTextInputFormatter.digitsOnly], inputFormatters: [FilteringTextInputFormatter.digitsOnly],
validator: (String? value) {
if (value == null || value.isEmpty) {
return "Loan day cannot be empty";
} else if (value is int) {
return "Please enter loan day in number";
} else {
return null;
}
},
), ),
), ),
actions: [ actions: [
...@@ -58,11 +67,14 @@ class _LoanBookForm extends State<LoanBookForm> { ...@@ -58,11 +67,14 @@ class _LoanBookForm extends State<LoanBookForm> {
), ),
FilledButton( FilledButton(
onPressed: () { onPressed: () {
authProvider.createMemberLoan( if (_formKey.currentState!.validate()) {}
authProvider.user!.accountId, authProvider
widget.bookId, .createMemberLoan(
int.parse(loanDayController.text), authProvider.user!.accountId,
); widget.bookId,
int.parse(loanDayController.text),
)
.then((_) => Navigator.of(context).pop());
}, },
child: const Text('Submit'), child: const Text('Submit'),
), ),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment