use of org.activityinfo.ui.client.input.model.FieldInput in project activityinfo by bedatadriven.
the class FormInputViewModelTest method inputMask.
@Test
public void inputMask() {
IntakeForm intakeForm = setup.getCatalog().getIntakeForm();
FormInputViewModelBuilder builder = builderFor(intakeForm);
FormInputModel inputModel = new FormInputModel(new RecordRef(intakeForm.getFormId(), ResourceId.generateId()));
// Fill in required fields
inputModel = inputModel.update(intakeForm.getOpenDateFieldId(), new LocalDate(2017, 1, 1));
// Does not match input mask "000"
inputModel = inputModel.update(intakeForm.getRegNumberFieldId(), new FieldInput(TextValue.valueOf("FOOOOO")));
FormInputViewModel viewModel = builder.build(inputModel);
assertThat(viewModel.isValid(), equalTo(false));
assertThat(viewModel.getValidationErrors(intakeForm.getRegNumberFieldId()), not(empty()));
}
use of org.activityinfo.ui.client.input.model.FieldInput in project activityinfo by bedatadriven.
the class AbstractWeekWidget method onDatePicked.
private void onDatePicked(ValueChangeEvent<Date> event) {
LocalDate date = new LocalDate(event.getValue());
dateMenu.hide();
updater.update(new FieldInput(periodType.containingDate(date)));
}
use of org.activityinfo.ui.client.input.model.FieldInput in project activityinfo by bedatadriven.
the class FormInputViewModel method buildUpdate.
public RecordUpdate buildUpdate(Optional<RecordRef> parentRef) {
RecordUpdate update = new RecordUpdate();
update.setRecordId(inputModel.getRecordRef().getRecordId());
update.setFormId(inputModel.getRecordRef().getFormId());
if (parentRef.isPresent()) {
update.setParentRecordId(parentRef.get().getRecordId().asString());
}
for (FormTree.Node node : formTree.getRootFields()) {
FieldInput newInput = inputModel.get(node.getFieldId());
if (newInput.getState() == FieldInput.State.VALID) {
update.setFieldValue(node.getFieldId(), newInput.getValue());
} else if (existingValues.containsKey(node.getFieldId()) && newInput.getState() == FieldInput.State.EMPTY) {
update.setFieldValue(node.getFieldId().asString(), Json.createNull());
} else if (existingValues.containsKey(node.getFieldId()) && !relevant.contains(node.getFieldId())) {
update.setFieldValue(node.getFieldId().asString(), Json.createNull());
}
}
return update;
}
use of org.activityinfo.ui.client.input.model.FieldInput in project activityinfo by bedatadriven.
the class FormInputViewModelBuilder method computeUpdatedRecord.
/**
* Computes the effective record, based
* @param existingValues
* @param inputModel
* @return
*/
private FormInstance computeUpdatedRecord(Map<ResourceId, FieldValue> existingValues, FormInputModel inputModel) {
// We inherit all the existing values...
FormInstance record = new FormInstance(ResourceId.generateId(), formTree.getRootFormId());
record.setAll(existingValues);
// Now apply changes...
for (FormTree.Node node : formTree.getRootFields()) {
FieldInput fieldInput = inputModel.get(node.getFieldId());
switch(fieldInput.getState()) {
case UNTOUCHED:
// No changes
break;
case EMPTY:
record.set(node.getFieldId(), (FieldValue) null);
break;
case VALID:
record.set(node.getFieldId(), fieldInput.getValue());
break;
case INVALID:
LOGGER.info("Field with invalid input = " + node.getFieldId());
record.set(node.getFieldId(), (FieldValue) null);
break;
}
}
LOGGER.info("fieldValues = " + record.getFieldValueMap());
return record;
}
use of org.activityinfo.ui.client.input.model.FieldInput in project activityinfo by bedatadriven.
the class GeoPointWidget method updateModel.
private void updateModel() {
latitude.parseAndValidate();
longitude.parseAndValidate();
if (latitude.empty && longitude.empty) {
// If both coordinates are empty, consider this to
// be an empty field and clear the field validation messages
// (the form may still mark this field as a whole if the field is
// required, but we don't have to deal with that here)
latitude.field.clearInvalid();
longitude.field.clearInvalid();
updater.update(FieldInput.EMPTY);
} else {
if (latitude.valid && longitude.valid) {
updater.update(new FieldInput(new GeoPoint(latitude.value, longitude.value)));
} else {
latitude.markInvalidIfEmpty();
longitude.markInvalidIfEmpty();
updater.update(FieldInput.INVALID_INPUT);
}
}
}
Aggregations