Git Product home page Git Product logo

Comments (3)

dkatzz avatar dkatzz commented on June 4, 2024

@Miguel-314 FYI! I'll plan to add some more of the technical details I found when looking into this as well

from civiform.

dkatzz avatar dkatzz commented on June 4, 2024

This is where we decide whether to show / hide a block:

This is where we make sure there is something selected in the predicate UI:

if (hasSelectionMissing && hasValueMissing) {
errorMessage =
'One or more form fields or dropdowns is missing an entry. Please fill out all form fields and dropdowns before saving.'
} else if (hasSelectionMissing) {
errorMessage =
'One or more dropdowns is missing a selection. Please fill out all dropdowns before saving.'
} else {
errorMessage =
'One or more form fields is missing an entry. Please fill out all form fields before saving.'
}
this.showErrorMessage(errorMessage)

When nothing is selected, the predicate doesn't match either of these key patterns because the predicate value is empty:

private static final Pattern SINGLE_PREDICATE_VALUE_FORM_KEY_PATTERN =
Pattern.compile("^group-(\\d+)-question-(\\d+)-predicateValue$");
private static final Pattern MULTI_PREDICATE_VALUE_FORM_KEY_PATTERN =
Pattern.compile("^group-(\\d+)-question-(\\d+)-predicateValues\\[\\d+\\]$");

from civiform.

dkatzz avatar dkatzz commented on June 4, 2024

The reason this is complicated is because if a question hasn't been seen / answered, the response won't be added to the applicant data (

return new PredicateEvaluator(this.applicantData, predicateGenerator)
) and the applicant data is what is compared with the predicate.

So my applicant data may look like this because I've only seen one question {"applicant":{"treeqdk":{"updated_at":1714146723403,"program_updated_in":7,"selections":["1"]}}}

But the predicate will look like this: $.applicant.sample_checkbox_question[?(@.selections noneof ["3", "2", "1"])]

So if the sample_checkbox_question is not in the applicant data, it won't be compared no matter what.

If an optional question is skipped, it is entered as so: {"applicant":{"treeqdk":{"updated_at":1714148097313,"program_updated_in":7}}}

We can consider either allowing for empty predicates to be set and if its empty we'd check that its absent or empty (like the optional situation above)

Maybe this would look something like !$.applicant.sample_checkbox_question || !$.applicant.sample_checkbox_question[?(@.selections)]

I think this would involve adding a new operator type of EMPTY or something like that

from civiform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.