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);
}
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");
});
}
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());
}
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");
}
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());
}
Aggregations