Search in sources :

Example 21 with TextField

use of com.vaadin.flow.component.textfield.TextField in project flow-components by vaadin.

the class Helper method createPersonEditor.

static CrudEditor<Person> createPersonEditor() {
    TextField firstName = new TextField("First name");
    firstName.getElement().setAttribute("editor-role", "first-name");
    TextField lastName = new TextField("Last name");
    lastName.getElement().setAttribute("editor-role", "last-name");
    FormLayout form = new FormLayout(firstName, lastName);
    Binder<Person> binder = new Binder<>(Person.class);
    binder.forField(firstName).asRequired().bind(Person::getFirstName, Person::setFirstName);
    binder.forField(lastName).withValidator(value -> value != null && value.startsWith("O"), "Only last names starting with 'O' allowed").bind(Person::getLastName, Person::setLastName);
    return new BinderCrudEditor<>(binder, form);
}
Also used : FormLayout(com.vaadin.flow.component.formlayout.FormLayout) FormLayout(com.vaadin.flow.component.formlayout.FormLayout) BinderCrudEditor(com.vaadin.flow.component.crud.BinderCrudEditor) CrudI18n(com.vaadin.flow.component.crud.CrudI18n) Binder(com.vaadin.flow.data.binder.Binder) TextField(com.vaadin.flow.component.textfield.TextField) CrudEditor(com.vaadin.flow.component.crud.CrudEditor) Binder(com.vaadin.flow.data.binder.Binder) TextField(com.vaadin.flow.component.textfield.TextField) BinderCrudEditor(com.vaadin.flow.component.crud.BinderCrudEditor)

Example 22 with TextField

use of com.vaadin.flow.component.textfield.TextField in project flow-components by vaadin.

the class CrudGrid method setupFiltering.

private void setupFiltering() {
    final HeaderRow filterRow = this.appendHeaderRow();
    getColumns().forEach(column -> {
        final TextField field = new TextField();
        field.getElement().setAttribute("crud-role", "Search");
        field.getElement().setAttribute("aria-label", "Filter by " + SharedUtil.propertyIdToHumanFriendly(column.getKey()));
        field.addValueChangeListener(event -> {
            filter.getConstraints().remove(column.getKey());
            if (!field.isEmpty()) {
                filter.getConstraints().put(column.getKey(), event.getValue());
            }
            super.getDataProvider().refreshAll();
        });
        field.setValueChangeMode(ValueChangeMode.EAGER);
        filterRow.getCell(column).setComponent(field);
        field.setSizeFull();
        field.setPlaceholder("Filter");
    });
}
Also used : HeaderRow(com.vaadin.flow.component.grid.HeaderRow) TextField(com.vaadin.flow.component.textfield.TextField)

Example 23 with TextField

use of com.vaadin.flow.component.textfield.TextField in project flow-components by vaadin.

the class EditorImplTest method save_editorIsOpened_editorIsInBufferedMode_beanIsInvalid_editorIsNotClosed.

@Test
public void save_editorIsOpened_editorIsInBufferedMode_beanIsInvalid_editorIsNotClosed() {
    editor.getBinder().forField(new TextField()).withValidator(value -> !value.equals("bar"), "").bind(ValueProvider.identity(), (item, value) -> {
    });
    editor.editItem("bar");
    fakeClientResponse();
    editor.refreshedItems.clear();
    editor.setBuffered(true);
    AtomicReference<StatusChangeEvent> statusEventCapture = new AtomicReference<>();
    AtomicReference<EditorEvent<String>> saveEventCapture = new AtomicReference<>();
    AtomicReference<EditorEvent<String>> closeEventCapture = new AtomicReference<>();
    Assert.assertFalse(doSave(statusEventCapture, saveEventCapture, closeEventCapture));
    Assert.assertEquals(0, editor.refreshedItems.size());
    Assert.assertNotNull(statusEventCapture.get());
    Assert.assertNull(saveEventCapture.get());
    Assert.assertNull(closeEventCapture.get());
    Assert.assertTrue(statusEventCapture.get().hasValidationErrors());
}
Also used : VaadinSession(com.vaadin.flow.server.VaadinSession) Grid(com.vaadin.flow.component.grid.Grid) ValueProvider(com.vaadin.flow.function.ValueProvider) Binder(com.vaadin.flow.data.binder.Binder) EditorImpl(com.vaadin.flow.component.grid.editor.EditorImpl) Test(org.junit.Test) EditorEvent(com.vaadin.flow.component.grid.editor.EditorEvent) StatusChangeEvent(com.vaadin.flow.data.binder.StatusChangeEvent) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) List(java.util.List) Rule(org.junit.Rule) UI(com.vaadin.flow.component.UI) Assert(org.junit.Assert) ExpectedException(org.junit.rules.ExpectedException) TextField(com.vaadin.flow.component.textfield.TextField) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) EditorEvent(com.vaadin.flow.component.grid.editor.EditorEvent) StatusChangeEvent(com.vaadin.flow.data.binder.StatusChangeEvent) TextField(com.vaadin.flow.component.textfield.TextField) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 24 with TextField

use of com.vaadin.flow.component.textfield.TextField in project flow-components by vaadin.

the class BeanGridTest method getEditor_editorHasBinder_binderIsAwareOfBeanProperties.

@Test
public void getEditor_editorHasBinder_binderIsAwareOfBeanProperties() {
    Editor<Person> editor = grid.getEditor();
    Binder<Person> binder = editor.getBinder();
    Assert.assertNotNull(binder);
    // Binder is aware about Person properties: otherwise it will throw
    binder.bind(new TextField(), "name");
    binder.bind(new TextField(), "born");
}
Also used : TextField(com.vaadin.flow.component.textfield.TextField) Test(org.junit.Test)

Example 25 with TextField

use of com.vaadin.flow.component.textfield.TextField in project flow-components by vaadin.

the class GridColumnEditorTest method setEditorComponent_setComponentl.

@Test
public void setEditorComponent_setComponentl() {
    Assert.assertNull(nameColumn.getEditorComponent());
    TextField field = new TextField();
    Column<Person> returnedColumn = nameColumn.setEditorComponent(field);
    Assert.assertEquals(nameColumn, returnedColumn);
    Assert.assertEquals(field, nameColumn.getEditorComponent());
}
Also used : TextField(com.vaadin.flow.component.textfield.TextField) Test(org.junit.Test)

Aggregations

TextField (com.vaadin.flow.component.textfield.TextField)227 Test (org.junit.jupiter.api.Test)61 Button (com.vaadin.flow.component.button.Button)54 Div (com.vaadin.flow.component.html.Div)38 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)32 FormLayout (com.vaadin.flow.component.formlayout.FormLayout)29 Binder (com.vaadin.flow.data.binder.Binder)29 GeneratedVaadinTextField (com.vaadin.flow.component.textfield.GeneratedVaadinTextField)28 Element (com.vaadin.flow.dom.Element)26 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)23 Route (com.vaadin.flow.router.Route)21 Component (com.vaadin.flow.component.Component)16 Checkbox (com.vaadin.flow.component.checkbox.Checkbox)15 BinderCrudEditor (com.vaadin.flow.component.crud.BinderCrudEditor)15 Grid (com.vaadin.flow.component.grid.Grid)15 Span (com.vaadin.flow.component.html.Span)15 List (java.util.List)15 EmailField (com.vaadin.flow.component.textfield.EmailField)14 TextArea (com.vaadin.flow.component.textfield.TextArea)14 Test (org.junit.Test)14