oTree Forum >

Retain <input> data given form validation failure

#1 by Mike_Zhiren_Wu

Dear all,

I'm currently designing a survey and I had some difficulty in retaining the previous entered data in <input> when the form validation fails. Here's part of my code and I wonder how should we tailor js script to make the previous entry not being wiped out?

    <input style="border: 1px solid #ccc; border-radius: 3px; height: 35px;" type="text" name="province" id="province"> province &nbsp <br>
    {{ formfield_errors 'province' }}
    <p style="margin-bottom:15px;"></p>
    <input style="border: 1px solid #ccc; border-radius: 3px; height: 35px;" type="text" name="city" id="city"> city &nbsp <br>
    {{ formfield_errors 'city' }}
    <p style="margin-bottom:15px;"></p>
    <input style="border: 1px solid #ccc; border-radius: 3px; height: 35px;" type="text" name="county" id="county"> county &nbsp
    {{ formfield_errors 'county' }}
    <p style="margin-bottom:30px;"></p>

#2 by olafghanizadeh

There is no straightforward way to do that, because the invalid data never goes to the database it is rejected by server side validation.

Write a reply

Set forum username