예제 #1
0
 def __init__(self,
              other_field,
              default=None,
              required=False,
              required_message=None,
              label=None):
     label = label or _('')
     super().__init__(default, required, required_message, label)
     self.add_validation_constraint(EqualToConstraint(other_field))
예제 #2
0
def test_equal_to_constraint_js(web_fixture, constraint_rendering_fixture):
    fixture = constraint_rendering_fixture

    class ModelObject:
        @exposed
        def fields(self, fields):
            fields.an_attribute = Field(label='an attribute')
            fields.other = Field(label='other attribute')

    model_object = ModelObject()
    other_field = model_object.fields.other
    constraint = EqualToConstraint(other_field, '$label, $other_label')

    class MyForm(Form):
        def __init__(self, view, name):
            super().__init__(view, name)
            field = fixture.model_object.fields.an_attribute.with_validation_constraint(
                constraint)
            other_input = self.add_child(
                TextInput(self, model_object.fields.other))
            other_input.set_id('other')
            one_input = self.add_child(TextInput(self, field))
            one_input.set_id('one')

    wsgi_app = web_fixture.new_wsgi_app(child_factory=MyForm.factory('myform'),
                                        enable_js=True)
    web_fixture.reahl_server.set_app(wsgi_app)

    web_fixture.driver_browser.open('/')

    web_fixture.driver_browser.type('//input[@id="other"]', 'something')
    web_fixture.driver_browser.type('//input[@id="one"]',
                                    'something else',
                                    trigger_blur=False,
                                    wait_for_ajax=False)
    web_fixture.driver_browser.press_tab()
    web_fixture.driver_browser.wait_for_element_visible(fixture.error_xpath)
    assert fixture.is_error_text('an attribute, other attribute')

    web_fixture.driver_browser.type('//input[@id="one"]',
                                    'something',
                                    trigger_blur=False,
                                    wait_for_ajax=False)
    web_fixture.driver_browser.press_tab()
    web_fixture.driver_browser.wait_for_element_not_visible(
        fixture.error_xpath)
예제 #3
0
파일: test_field.py 프로젝트: diopib/reahl
    def equal_to_constraint(self, fixture):
        other_field = Field(label='other')
        equal_to_constraint = EqualToConstraint(other_field, '$label, $other_label')
        other_field.set_user_input('should be equal to this string', ignore_validation=True)

        #case: valid input
        with expected(NoException):
            equal_to_constraint.validate_parsed_value('should be equal to this string' )

        #case: invalid input
        with expected(EqualToConstraint):
            equal_to_constraint.validate_parsed_value('this is not equal')