masonite icon indicating copy to clipboard operation
masonite copied to clipboard

Old helper is missing the default value parameter

Open tpow opened this issue 2 years ago • 0 comments

Describe the bug

While trying to upgrade a project from Masonite v3 to v4 I noticed that the "old" helper no longer has the default value option. This makes it awkward to use in certain cases and is an unnecessary upgrade pain point.

It looks like it would be easy to implement. Something like this should work In sessions/helpers.py:

def old(key: str, default="") -> str:                                                                
      """Helper used to get value from session for the given key."""               
      return Session.get(key) or default

Alternatively, I might be able to use a construct like this in the templates, but I am not sure that will work correctly and makes the template somewhat confusing:

<input value="{{ old('amount') or '0.0' }}">

Expected behaviour

No response

Steps to reproduce the bug

No response

Screenshots

No response

OS

Linux

OS version

Ubuntu LTS

Browser

Safari 16

Masonite Version

4.17.4

Anything else ?

No response

tpow avatar Mar 17 '23 12:03 tpow