from nagare import editor, presentation, component, validator
class Option:
def __init__(self):
self.option2 = 'opt1'
self.option_result = ''
class OptionEditor(editor.Editor):
def __init__(self, option):
self.list1 = ['a', 'b', 'c']
self.list2 = ['1', '2', '3']
self.option = 'opt1'
super(OptionEditor, self).__init__(option, ('option_result', 'option2'))
def test(self, opt):
self.option = opt
def commit(self):
super(OptionEditor, self).commit(('option_result'))
@presentation.render_for(OptionEditor)
def render(self, h, comp, *args):
with h.form:
h << 'option1 ' << h.input(type='radio', name='option').action(self.test('opt1')).selected(self.option == 'opt1') << h.br #<< h.a('X').action(self.test('opt1')) << h.br h << 'option2 ' << h.input(type='radio', name='option').action(self.test('opt2')).selected(self.option == 'opt2') << h.br #<< h.a('X').action(self.test('opt2')) << h.br
with h.select(multiple='multiple').action(self.option_result):
if self.option == 'opt1':
with h.optgroup(label='Option 1'):
for i in self.list1 :
h << h.option(i, value=i).selected(self.option_result())
else :
with h.optgroup(label='Option 2'):
for i in self.list2 :
h << h.option(i, value=i).selected(self.option_result())
return h.root
class App:
def __init__(self):
self.option = Option()
editor = OptionEditor(self.option)
self.editor_component = component.Component(editor)
@presentation.render_for(App)
def render(self, h, *args):
h << self.editor_component
return h.root
app = App
Despite the choice made, 'option' is always equal to 'opt2', and i don't understand why.