Search in sources :

Example 66 with FormEntryPrompt

use of org.javarosa.form.api.FormEntryPrompt in project javarosa by opendatakit.

the class RecalculateTest method testComputedConstraintText.

@Test
public void testComputedConstraintText() {
    FormIndex nowNoteField = new FormIndex(0, 0, formDef.getMainInstance().getRoot().getChild("now_note", 0).getRef());
    String actualQuestionText = new FormEntryPrompt(formDef, nowNoteField).getQuestionText();
    assertEquals("2018-01-01T10:20:30.400", actualQuestionText);
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) FormIndex(org.javarosa.core.model.FormIndex) Test(org.junit.Test)

Example 67 with FormEntryPrompt

use of org.javarosa.form.api.FormEntryPrompt in project javarosa by opendatakit.

the class FormDefTest method setUp.

public void setUp() {
    fpi = new FormParseInit();
    q = fpi.getFirstQuestionDef();
    fep = new FormEntryPrompt(fpi.getFormDef(), fpi.getFormEntryModel().getFormIndex());
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) FormParseInit(org.javarosa.core.test.FormParseInit)

Example 68 with FormEntryPrompt

use of org.javarosa.form.api.FormEntryPrompt in project javarosa by opendatakit.

the class TextFormTests method setUp.

public void setUp() {
    fpi = new FormParseInit();
    q = fpi.getFirstQuestionDef();
    fep = new FormEntryPrompt(fpi.getFormDef(), fpi.getFormEntryModel().getFormIndex());
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) DummyFormEntryPrompt(org.javarosa.core.model.test.DummyFormEntryPrompt) FormParseInit(org.javarosa.core.test.FormParseInit)

Example 69 with FormEntryPrompt

use of org.javarosa.form.api.FormEntryPrompt in project javarosa by opendatakit.

the class TextFormTests method testPromptsWithLocalizer.

public void testPromptsWithLocalizer() {
    Localizer l = new Localizer();
    TableLocaleSource table = new TableLocaleSource();
    l.addAvailableLocale("locale");
    l.setDefaultLocale("locale");
    table.setLocaleMapping("prompt;long", "loc: long text");
    table.setLocaleMapping("prompt;short", "loc: short text");
    table.setLocaleMapping("help", "loc: help text");
    l.registerLocaleResource("locale", table);
    l.setLocale("locale");
    QuestionDef q = new QuestionDef();
    q.setHelpTextID("help");
    FormEntryPrompt fep = new DummyFormEntryPrompt(l, "prompt", q);
    if (!"loc: long text".equals(fep.getLongText())) {
        fail("Long text did not localize properly");
    }
    if (!"loc: short text".equals(fep.getShortText())) {
        fail("Short text did not localize properly");
    }
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) DummyFormEntryPrompt(org.javarosa.core.model.test.DummyFormEntryPrompt) DummyFormEntryPrompt(org.javarosa.core.model.test.DummyFormEntryPrompt) TableLocaleSource(org.javarosa.core.services.locale.TableLocaleSource) Localizer(org.javarosa.core.services.locale.Localizer) QuestionDef(org.javarosa.core.model.QuestionDef)

Example 70 with FormEntryPrompt

use of org.javarosa.form.api.FormEntryPrompt in project collect by opendatakit.

the class FormEntryActivity method updateFieldListQuestions.

/**
 * Saves the form and updates displayed widgets accordingly:
 * - removes widgets corresponding to questions that are no longer relevant
 * - adds widgets corresponding to questions that are newly-relevant
 * - removes and rebuilds widgets corresponding to questions that have changed in some way. For
 * example, the question text or hint may have updated due to a value they refer to changing.
 * <p>
 * The widget corresponding to the {@param lastChangedIndex} is never changed.
 */
private void updateFieldListQuestions(FormIndex lastChangedIndex) throws RepeatsInFieldListException {
    // Save the user-visible state for all questions in this field-list
    FormEntryPrompt[] questionsBeforeSave = getFormController().getQuestionPrompts();
    List<ImmutableDisplayableQuestion> immutableQuestionsBeforeSave = new ArrayList<>();
    for (FormEntryPrompt questionBeforeSave : questionsBeforeSave) {
        immutableQuestionsBeforeSave.add(new ImmutableDisplayableQuestion(questionBeforeSave));
    }
    saveAnswersForCurrentScreen(questionsBeforeSave, immutableQuestionsBeforeSave);
    FormEntryPrompt[] questionsAfterSave = getFormController().getQuestionPrompts();
    Map<FormIndex, FormEntryPrompt> questionsAfterSaveByIndex = new HashMap<>();
    for (FormEntryPrompt question : questionsAfterSave) {
        questionsAfterSaveByIndex.put(question.getIndex(), question);
    }
    // Identify widgets to remove or rebuild (by removing and re-adding). We'd like to do the
    // identification and removal in the same pass but removal has to be done in a loop that
    // starts from the end and itemset-based select choices will only be correctly recomputed
    // if accessed from beginning to end because the call on sameAs is what calls
    // populateDynamicChoices. See https://github.com/getodk/javarosa/issues/436
    List<FormEntryPrompt> questionsThatHaveNotChanged = new ArrayList<>();
    List<FormIndex> formIndexesToRemove = new ArrayList<>();
    for (ImmutableDisplayableQuestion questionBeforeSave : immutableQuestionsBeforeSave) {
        FormEntryPrompt questionAtSameFormIndex = questionsAfterSaveByIndex.get(questionBeforeSave.getFormIndex());
        // bypass SelectChoices stored in ImmutableDisplayableQuestion
        if (questionBeforeSave.sameAs(questionAtSameFormIndex) && !getFormController().usesDatabaseExternalDataFeature(questionBeforeSave.getFormIndex())) {
            questionsThatHaveNotChanged.add(questionAtSameFormIndex);
        } else if (!lastChangedIndex.equals(questionBeforeSave.getFormIndex())) {
            formIndexesToRemove.add(questionBeforeSave.getFormIndex());
        }
    }
    for (int i = immutableQuestionsBeforeSave.size() - 1; i >= 0; i--) {
        ImmutableDisplayableQuestion questionBeforeSave = immutableQuestionsBeforeSave.get(i);
        if (formIndexesToRemove.contains(questionBeforeSave.getFormIndex())) {
            odkView.removeWidgetAt(i);
        }
    }
    for (int i = 0; i < questionsAfterSave.length; i++) {
        if (!questionsThatHaveNotChanged.contains(questionsAfterSave[i]) && !questionsAfterSave[i].getIndex().equals(lastChangedIndex)) {
            // The values of widgets in intent groups are set by the view so widgetValueChanged
            // is never called. This means readOnlyOverride can always be set to false.
            odkView.addWidgetForQuestion(questionsAfterSave[i], i);
        }
    }
}
Also used : ImmutableDisplayableQuestion(org.odk.collect.android.logic.ImmutableDisplayableQuestion) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FormIndex(org.javarosa.core.model.FormIndex) FailedConstraint(org.odk.collect.android.javarosawrapper.FormController.FailedConstraint)

Aggregations

FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)114 Test (org.junit.Test)92 MockFormEntryPromptBuilder (org.odk.collect.android.support.MockFormEntryPromptBuilder)45 Clip (org.odk.collect.audioclips.Clip)13 FormIndex (org.javarosa.core.model.FormIndex)10 File (java.io.File)9 SelectChoice (org.javarosa.core.model.SelectChoice)7 StringData (org.javarosa.core.model.data.StringData)7 IFormElement (org.javarosa.core.model.IFormElement)5 QuestionDef (org.javarosa.core.model.QuestionDef)5 FormController (org.odk.collect.android.javarosawrapper.FormController)5 GroupDef (org.javarosa.core.model.GroupDef)4 QuestionDetails (org.odk.collect.android.formentry.questions.QuestionDetails)4 DatePickerDetails (org.odk.collect.android.logic.DatePickerDetails)4 ArrayList (java.util.ArrayList)3 DateData (org.javarosa.core.model.data.DateData)3 IAnswerData (org.javarosa.core.model.data.IAnswerData)3 TreeReference (org.javarosa.core.model.instance.TreeReference)3 LocalDateTime (org.joda.time.LocalDateTime)3 AudioControllerView (org.odk.collect.android.audio.AudioControllerView)3