Skip to content
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

Remembered fields feature #200

Merged
merged 5 commits into from Oct 25, 2017

Conversation

hughbris
Copy link
Contributor

@hughbris hughbris commented Oct 5, 2017

I've used this simple hack successfully and it would certainly suit me to have it integrated.

The 'remember' processing instruction is useful in scenarios where a user is expected to repeatedly use a form and will want certain fields to be pre-populated with their values from last time. Obviously this is only appropriate in private user environments.

My use case was a medical referral form. Referring practitioners do not need to re-enter their own details each subsequent time they complete the form and can concentrate on patient details.

Here is the relevant form YAML:

    - name: practitioner-name
        label: Practitioner name
        type: text
        hint: You will only need to complete this once per browser/device. It should be recalled subsequent occasions.
        validate:
            required: true

    - name: practitioner-address
        type: textarea
        label: Your address
        rows: 3
        placeholder: 'Your postal address for correspondence, including postcode'
        validate:
            required: true

    - name: practitioner-phone
        type: text
        label: Your phone
        validate:
            required: true

    - name: practitioner-email
        type: email
        label: Your email
        validate:
            required: true

and further down:

    - remember:
        - practitioner-name
        - practitioner-address
        - practitioner-phone
        - practitioner-email

There's an extraneous edited line where the honeypot code is that I couldn't eliminate, sorry about that

@rhukster rhukster merged commit 54b046c into getgrav:develop Oct 25, 2017
@rhukster
Copy link
Member

A useful feature.. just need to remember to document it!

@@ -2,6 +2,8 @@
{% set toggleableChecked = field.toggleable and (originalValue is not null and originalValue is not empty) %}
{% set isDisabledToggleable = field.toggleable and not toggleableChecked %}
{% set value = (is_object(value) or value is null ? field.default : value) %}
{% set cookie_name = 'forms-' ~ form.name ~ '-' ~ field.name %}
{% set value = (is_object(value) or value is null ? (get_cookie(cookie_name) is null ? field.default : get_cookie(cookie_name)) : value) %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hughbris I had to remove the check for is_object() as it breaks some other fields taking objects as values. Was there any reason why you had it there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry I can't remember precisely but I have a feeling something failed without that check. You might have to test on some object-type fields, can't even recall what they were :/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hughbris Please check the next beta.5 when it gets out.

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

Successfully merging this pull request may close these issues.

None yet

3 participants