-
Notifications
You must be signed in to change notification settings - Fork 80
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
Conversation
…ng to add any data properties defined in the field's YAML
…ied previous field values on reload
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) %} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :/
There was a problem hiding this comment.
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.
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:
and further down:
There's an extraneous edited line where the honeypot code is that I couldn't eliminate, sorry about that