-
Notifications
You must be signed in to change notification settings - Fork 259
Open
Description
hi,
i'm relative new to flexx, but what i tried / seen so far is really nice 👍 .
for a little project of mine, i'm trying to build a single page application or a software as a service.
currently i'm researching/testing form<->model handling/validation.
is there an how-to or a guide about two-way-data-binding?
what i have seen/tried so far is relative cumbersome.
class MyForm(flx.Widget):
data_model = flx.DictProp(
{'no': '1', 'name': 'Test', 'desc': 'Desc', 'dyn': 'Dyn'})
def init(self, data=None):
super().init()
with flx.FormLayout():
self.form_no = flx.LineEdit(title='No.:')
self.form_name = flx.LineEdit(title='Name:')
self.form_desc = flx.MultiLineEdit(title='Description:')
with flx.HBox():
self.save_btn = flx.Button(text='Save')
flx.Widget(flex=1) # Add a spacer
self.update_model(data)
@flx.reaction('form_no.user_done')
def update_no(self, *events):
data = {
'no': events[-1]['new_value']
}
self.update_model(data)
@flx.action
def update_model(self, data):
if data is None:
return
self._mutate_data_model(data, 'replace', -1)
@flx.action
def model_to_form(self):
self.form_no.set_text(self.data_model['no'])
self.form_name.set_text(self.data_model['name'])
self.form_desc.set_text(self.data_model['desc'])
@flx.reaction('save_btn.pointer_click')
def save_form(self, *events):
print(repr(self.data_model))
@flx.reaction('data_model')
def print_model(self, *events):
print(repr(self.data_model))
self.model_to_form()
class MyUI(flx.Widget):
def init(self):
super().init()
with flx.HBox():
self.form = MyForm(flex=1)
class MyApp(flx.PyComponent):
def init(self):
super().init()
self.ui = MyUI()
if __name__ == '__main__':
app = flx.App(MyApp)
app.launch('browser')
flx.start()having to map each field of the form to the model and back... not very user friendly.
greetings
nolan
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels