susanBuck / e15-spring22

0 stars 0 forks source link

Unable to supply default value for form text field #70

Closed luannebe closed 2 years ago

luannebe commented 2 years ago

Hi, I would like to supply a default value for a form field. The following works, except that the default value is displayed in the form and saved as "Massachusetts" not "Massachusetts Ave NW." Any thoughts would be much appreciated.

<div class="col-6">
    <label for="street_name" class="form-label">*Street Name</label>
    <input type="text" class="form-control" id="street_name" name="street_name" value={{ old("street_name",  "Massachusetts Ave NW") }}>   
    @include('includes/error-field', ['fieldName' => 'street_name'])      
</div>
image
pllealfunes commented 2 years ago

What if you move your quotation mark from the end of Massachusetts to after nw? So that it can be value="Massachusetts Ave NW"

luannebe commented 2 years ago

Hi, Oh, sorry. I should have explained this better. The upper block is from my code. You have to use the horizontal scroll bar to see all of it. The lower block is a screen shot of the form field html in the browser, as shown by the Chrome Elements inspector. Somehow, the string up to the first white space gets enclosed in quotes, and the rest is floating to the right.

gkorodi commented 2 years ago

Maybe there is just an extra quote missing from the input element?!

I tried and this seems to work

<input type="text" class="form-control" id="street_name" name="street_name" value="{{ old("street_name", "Massachusetts Ave NW") }}">

or more closely

.... value="{{ ..... }}" />

I think the quotes needed around the whole value that you are printing in the blade template.

luannebe commented 2 years ago

Brilliant!!! it works. Thank you @gkorodi and @pllealfunes !