Skip to content

Consider publishing xforms cheat sheet #386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mrjones-plip opened this issue Dec 10, 2020 · 0 comments
Open

Consider publishing xforms cheat sheet #386

mrjones-plip opened this issue Dec 10, 2020 · 0 comments

Comments

@mrjones-plip
Copy link
Contributor

mrjones-plip commented Dec 10, 2020

I'm writing my first form in medic/cht-core#6727 and think it'd be helpful to new app builders if we documented some top used tricks when building an xlsx

brain dump:

  • it can be nice to use google docs to synchronize/archive your xlsx (but cloud is not a backup!) also - see current issue on Improvements pulling files from Google Drive #381
  • only show a field when prior select_one or multi_select field is filled out a specific way: set relevent to selected(${attend_clinic}, 'yes')
  • only show a field when prior value is not selected: set relevent to not(selected(${attend_clinic}, 'yes'))
  • require a date to be in the future (invert > to be in past): constraint to decimal-date-time(.) >= floor(decimal-date-time(today()))
  • make patient's age in available in the form:
    • ensure there's a type/name/appearance entry of: db:person/ _id/db-object
    • and another of type/name entry of: hidden/date_of_birth
  • Make patient's age avail in years: type/name/calculation of calculate/patient_age_in_years/floor( difference-in-months( ${date_of_birth}, today() ) div 12 )
  • Make patient's age avail in months: type/name/calculation of calculate/patient_age_in_months/difference-in-months( ${date_of_birth}, today() )
  • Make patient's age avail in days: type/name/calculation of calculate/patient_age_in_days/floor(decimal-date-time(today()) - decimal-date-time(${date_of_birth}) )
  • group a set of fields together on a page: appearance to field-list
  • how to debug a field's current values: in dev console paste window.debugFormModel(). also see forum post
  • tips on how to format a summary page:
    • multiple formatting h1 yellow center
    • use of raw HTML including font awesome
    • which icons you can use - list is here, but how to actually use those icons? use font awesome or include .svg? (answer - it's always use FA in headers - see
  • show appropriate formatted age:
    if(${patient_age_in_days} < 31, 
    concat(${patient_age_in_days}, ' days old'),
    if(${patient_age_in_months} < 12, 
    concat(${patient_age_in_months}, ' months old'), 
    concat(${patient_age_in_years}, ' years old')))
    
  • get 1 day from today() (or from a user input date with ${input}): format-date-time(date-time(floor(decimal-date-time(today())) + 1), "%Y-%m-%d")
  • require a date input to be within next 7 days, set constraint to decimal-date-time(.) >= floor(decimal-date-time(today())) and decimal-date-time(.) <= floor(decimal-date-time(today() + 7))
  • show values of form in JS console: window.debugFormModel();
  • remind folks of the use of numbers for choices instead ascii text names. this allows you to use both selected() logic as well as < operators
  • xlsform website
  • Tasks can't be assigned to admin users, "Tasks are available only for users of type “restricted to their place"" - per our docs.
  • Offline users won't work on http (non SSL) connections unless you're on localhost. Either user Admin user to be an online user or use ngrok or DIY to enable SSL.
  • You want to have a multi-select (select_multiple) with a "none of the above" option that doesn't allow them to select any other options. Set constraint to not(selected(.,'none') and count-selected(.)>1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant