Opened 4 years ago

Closed 4 years ago

#16851 closed Uncategorized (fixed)

Accessing a forms field value in a template

Reported by: from_a_far@… Owned by: yasar11732
Component: Documentation Version: 1.3
Severity: Normal Keywords:
Cc: yasar11732 Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: yes UI/UX: no

Description

Please could someone put in the documentation that you can access a forms field value in a template by using the following

{{ form.apple.value }}

I only ask because I couldn't find anything on the web about and it's only by trying it that I found it worked

Attachments (2)

form_value.diff (654 bytes) - added by yasar11732 4 years ago.
Added required documentation items
0001-Added-field.value-explanation.patch (827 bytes) - added by yasar11732 4 years ago.
Removed extra remarks about null value

Download all attachments as: .zip

Change History (12)

comment:1 Changed 4 years ago by carljm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 4 years ago by linovia

Actually, {{ form.apple.value }} will not be correct if value is None.
{{ form.apple.value|default_if_none:"" }} is a better choice.

comment:3 Changed 4 years ago by yasar11732

  • Cc yasar11732 added
  • Owner changed from nobody to yasar11732
  • Status changed from new to assigned

Changed 4 years ago by yasar11732

Added required documentation items

comment:4 Changed 4 years ago by yasar11732

  • Has patch set
  • Triage Stage changed from Accepted to Ready for checkin

comment:5 Changed 4 years ago by yasar11732

  • Cc yasar11732 removed

comment:6 Changed 4 years ago by yasar11732

  • Cc yasar11732 added

comment:7 Changed 4 years ago by aaugustin

  • Triage Stage changed from Ready for checkin to Accepted

See #16758 - same comment. Also, note that you don't need to add yourself in Cc explicitly. If you've contributed to a ticket (written a comment, uploaded a patch...) Trac will always notify you of updates.

comment:8 Changed 4 years ago by bpeschier

  • Patch needs improvement set

Nice and simple addition to the docs, but I do not really agree with the remark about it not being "correct" and one "should" use the default filter: an empty string is not technically None either. Encountering None in templates is something more general and does not need to get mentioned here.

Changed 4 years ago by yasar11732

Removed extra remarks about null value

comment:9 Changed 4 years ago by krzysiumed

  • Triage Stage changed from Accepted to Ready for checkin

comment:10 Changed 4 years ago by timo

  • Resolution set to fixed
  • Status changed from assigned to closed

In [17138]:

Fixed #16851 - Added how-to access form field value in template; thanks yasar11732 for the patch.

Note: See TracTickets for help on using tickets.
Back to Top