
from reahl.web.fw import UserInterface
from reahl.web.bootstrap.page import HTML5Page
from reahl.web.bootstrap.forms import Form, TextInput, FormLayout
from reahl.component.modelinterface import exposed, EmailField

class ValidationUI(UserInterface):
    def assemble(self):
        self.define_view('/', title='Validation demo', page=HomePage.factory())


class HomePage(HTML5Page):
    def __init__(self, view):
        super().__init__(view)
        self.body.add_child(CommentForm(view))


class Comment:
    @exposed
    def fields(self, fields):
        fields.email_address = EmailField(label='Email address', required=True)


class CommentForm(Form):
    def __init__(self, view):
        super().__init__(view, 'myform')

        new_comment = Comment()
        self.use_layout(FormLayout())
        self.layout.add_input( TextInput(self, new_comment.fields.email_address) )





@@ -145,16 +145,29 @@
 rmLayout
+, ButtonInput
 %0Afrom re
@@ -221,16 +221,23 @@
 ailField
+, Event
 %0A%0Aclass 
@@ -646,16 +646,114 @@
 d=True)%0A
+    %0A    @exposed%0A    def events(self, events):%0A        events.do_nothing = Event(label='Submit')%0A
 %0A%0Aclass 
@@ -913,16 +913,16 @@
 yout())%0A
-
         
@@ -997,11 +997,150 @@
 ess) )%0A%0A
+        self.define_event_handler(new_comment.events.do_nothing)%0A        self.add_child(ButtonInput(self, new_comment.events.do_nothing))%0A%0A
 %0A%0A%0A

add event to example to avoid users seeing errors when submitting the form - used to break by design - complicates example with events