[Fixed]-Django Form Wizard โ€“ Setting default value for text input field

1๐Ÿ‘

โœ…

I think you can do it simply in the widget, just test, if val is empty and if it is, then put in your default value like this:

def create_input(self, name, field, value, val, none_value):
    if 'id' in self.attrs:
        id_ = self.attrs['id']
    else:
        id_ = 'id+%s' % name
    local_attrs = self.build_attrs(id=field % id_)
    inp = TextInput()
    if val == None or val == '': 
        val = '2015-11-29' # or use datetime.now(), or compute another good default
    select_html = inp.render(field % name, val, local_attrs)
    return select_html
๐Ÿ‘คgilhad

Leave a comment