-
Hi 👋 I'm currently working on a feature that involves form filtering using Here's a simplified version of my form: class FilterBuildingsForm extends NyFormData {
FilterBuildingsForm() : super("filter_buildings");
FormValidator validator = FormValidator.custom((value) {
num val = double.tryParse(value) ?? -1;
if (value == null || value.isEmpty) return true;
return val >= 0;
}, message: "You can't enter below 0");
@override
fields() => [
Field.number("minPrice", hidden: true, validate: validator),
Field.number("maxPrice", hidden: true, validate: validator),
// ... more fields ...
];
} I use this in a screen with However, when the user navigates back to the screen, the form resets, even though I'd like it to remember the last state until it's manually cleared. It would be great if
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @B3K4682, It would be a nice feature. If I get time I'll explore this more. Your Controllerclass ReportController extends Controller {
ReportAnIssueForm form = ReportAnIssueForm();
@override
bool get singleton => true;
} NyPageclass ReportAnIssuePage extends NyStatefulWidget<ReportController> {
static RouteView path = ("/report-an-issue", (_) => ReportAnIssuePage());
ReportAnIssuePage({super.key}) : super(child: () => _ReportAnIssuePageState());
}
class _ReportAnIssuePageState extends NyPage<ReportAnIssuePage> {
@override
Widget view(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Report An Issue")
),
body: SafeArea(
child: NyForm(form: widget.controller.form),
),
);
}
} |
Beta Was this translation helpful? Give feedback.
Hi @B3K4682,
It would be a nice feature. If I get time I'll explore this more.
I think for now though, you could just use a singleton
Controller
for your page and then create the Form instance in there.Your Controller
NyPage