-1

I'm pre-populating a form using data from dynamodb. I'm passing all the content in as part of the render_template statement:

return render_template('edit_ride_input.html', 
                          rideDate=item.get('ride_date'),
                          rideLocation=item.get('ride_location'),
                          rideLevel=item.get('ride_level'),
                          rideCap=item.get('ride_cap'),
                          rideVis=item.get('ride_vis'),
                          rideRange=item.get('ride_range'),
                          rideReg=item.get('ride_reg'),
                          rideFuel=item.get('ride_fuel'),
                          rideLunch=item.get('ride_lunch'),
                          rideMeetLocation=item.get('ride_meet_location'),
                          rideMeetTime=item.get('ride_meet_time'),
                          rideUnloadTime=item.get('ride_unload_time'),
                          rideUnloadLocation=item.get('ride_unload_location'),
                          rideDescription=item.get('ride_description'))

I then use the value= attribute on each of the form elements to pre-populate the data:

<div class="form-group ">
    <label class="col-md-4 control-label" for="ride_date">*Date:</label>
    <div class="col-md-4">
        <input id="ride_date" name="ride_date" value={{rideDate}} type="text" placeholder="DD/MM/YYYY" class="form-control" required="" />
    </div>
</div>
<!-- Text input-->
<div class="form-group">
    <label class="col-md-4 control-label" for="ride_location">*Location:</label>
    <div class="col-md-4">
        <h1>{{rideLocation}}
        <input id="ride_location" name="ride_location" value= {{rideLocation}} type="text" placeholder="Where is the ride being held?" class="form-control input-md" required="">
    </div>

The problem is, when the form is rendered, it only shows the data from the variables up to the first whitespace. For example, if I pass in rideLocation with a value of "Nightcap National Park" all that will appear in the input field is "Nightcap". I know the variable contains the full string, because when I render it directly in the page as {{rideLocation}} I see "Nightcap National Park"

Am I doing something wrong?

Kelly Norton
  • 487
  • 2
  • 4
  • 19

1 Answers1

1

Typing things out really makes you think, and when I think, sometimes my brain actually works :)

It occurred to me that when entering the pre-populate values directly, they need to be wrapped in quotation marks. I figured the flask variables would be no different, so I tried wrapping them in quotes as well:

<div class="form-group ">
    <label class="col-md-4 control-label" for="ride_date">*Date:</label>
    <div class="col-md-4">
        <input id="ride_date" name="ride_date" value="{{rideDate}}" type="text" placeholder="DD/MM/YYYY" class="form-control" required="" />
    </div>
</div>
<!-- Text input-->
<div class="form-group">
    <label class="col-md-4 control-label" for="ride_location">*Location:</label>
    <div class="col-md-4">
        <h1>{{rideLocation}}
        <input id="ride_location" name="ride_location" value= "{{rideLocation}}" type="text" placeholder="Where is the ride being held?" class="form-control input-md" required="">
    </div>

And what do you know, it worked!

Hopefully this helps someone else out in the future.

Kelly Norton
  • 487
  • 2
  • 4
  • 19