Retaining text in search input boxes

151 views
Skip to first unread message

Dick Arnold

unread,
Feb 15, 2020, 1:50:59 PM2/15/20
to Django users
I have a personnel database which has to be edited to keep it current.
I have created search parameters to find the person to edit.
The exact name of the person is not always known, therefore the name field for searching can contain only a few of the characters.  This can create a list of several people.
After the search parameters are entered a "Search" button is clicked and the output, if any, is displayed in a table.
If the search parameters need to be improved, I want the original (current) search argument to be retained in the argument field so I do not need to re-type ALL the search parameters, just the ones I want to change.

I have not been able to find a way to retain the value in the search input box,

Does anyone know how to accomplish this?

Here's the input for one of the input boxes.

<input type="text" id="name_id" name="name_id" placeholder="Enter a few characters">

onlinejudge95

unread,
Feb 15, 2020, 2:16:18 PM2/15/20
to django...@googlegroups.com
Set an attribute of value in your input tags, and use the form object in your view to populate it. For reference https://stackoverflow.com/questions/4880306/django-multiple-forms-and-keep-field-data-input-after-submission?rq=1 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/92cfccd1-5916-4817-ae46-c612aa462610%40googlegroups.com.

maninder singh Kumar

unread,
Feb 16, 2020, 12:56:25 AM2/16/20
to django...@googlegroups.com
Wouldn't the value field make it fixed ?
 
               
 


On Sun, Feb 16, 2020 at 12:22 AM Dick Arnold <darno...@gmail.com> wrote:
--

onlinejudge95

unread,
Feb 17, 2020, 7:19:55 AM2/17/20
to django...@googlegroups.com
On Sun, Feb 16, 2020 at 11:26 AM maninder singh Kumar <maninder...@gmail.com> wrote:
Wouldn't the value field make it fixed ?
Sure but you can always grab what value to insert from your views. If it is the first time form is being filled than simply use nothing as value, if the user tries to submit the form and have an error then just fill the values with corresponding data 

Dick Arnold

unread,
Feb 20, 2020, 5:14:18 AM2/20/20
to Django users
I used a value of {{attribute value}}.  so it is nor a fixed value, but is the value submitted.  Doesn't work well for drop down input fields.  still researching.

Dick Arnold

unread,
Feb 20, 2020, 5:15:25 AM2/20/20
to Django users

Dick Arnold

unread,
Feb 20, 2020, 5:17:35 AM2/20/20
to Django users
I should have said {{attribute name}}, not value.


On Saturday, February 15, 2020 at 12:50:59 PM UTC-6, Dick Arnold wrote:

Farai M

unread,
Feb 20, 2020, 5:55:23 AM2/20/20
to django...@googlegroups.com
For drop downs use JavaScript script or JQuery to set the value of the value of the selected item.For input use an if on the value if it's populated then the input value is equal to the attribute us you put it .Another option is to use the default on attribute but make it an empty string so you don't have none when attribute is empty .

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

onlinejudge95

unread,
Feb 20, 2020, 8:52:05 AM2/20/20
to django...@googlegroups.com

Dick Arnold

unread,
Mar 27, 2020, 1:57:26 PM3/27/20
to Django users
Sorry about the amount of time it has taken me respond to your post.  I have been in the hospital.
I have been able to fix everything except the drop down boxes.  I'll show some code first.

    <div class="row">
      <div class="col-25">
        <label for="ctype_id">Contact Type</label>
      </div>
      <div class="col-75">
        <select name='ctype_id'>
          <option value=" ">        </option>
          <option value="P">P Player</option>
          <option value="V">V Vendor</option>
        </select>
          <input type="text" id="ctype_id" hidden value="{{ctype_id}}">
      </div>
    </div>

I've been able to use the 'value' attribute to retain the search option that was chosen.  The field is actually defined as 'character' with a max length of 1.  This technique does not work for drop down lists.  The input field (box) still contains nothing.  I erased the 'hidden' word as I couldn't decide what it did.  It created a second input field (box) below the original box, so now I have two input boxes for this operation.  The second box does show the correct, one character value that was entered.  But is need to put it in the first box, not the second. 

I tried another technique, but it does the same thing.  Here is that code (it's for a different drop down list):

    <div class="row">
      <div class="col-25">
        <label for="ltype_id">Level of Play</label>
      </div>
      <div class="col-75">
        <select name='ltype_id'>
          <option value=" ">          </option>
          <option value="A">A Advanced</option>
          <option value="N">N Novice  </option>
          <option value="O">O Open    </option>
          <option value="U">U Unknown </option>
        </select>
          <input type="text" id="ltype_id" hidden value="{{ltype_id}}"
                 onclick="retainLParm">
      </div>
    </div>
      <script>
        function retainLParm() {
          document.getElementById("ltype_id").defaultValue="{{ltype_id}}";
        }
      </script>

Have I missed something that was In your post?  I've read and tried every thing I could.  I'm getting very frustrated.  The problem is...  I'm a mainframe programmer.  Python and Django and HTML and CSS are all brand new for me.  I'm getting better though.

Thanks for any help.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.

Dick Arnold

unread,
Mar 29, 2020, 10:35:20 AM3/29/20
to Django users
Your solution was to set the 'value' attribute to the value that was entered in the input box.  That worked for the text input with the exception of the ones that got their value from a drop down list.  Please see my html code elsewhere in this post.  If you have any ideas, I would really appreciate it.  Thanks for your previous ideas.


On Saturday, February 15, 2020 at 1:16:18 PM UTC-6, OnlineJudge95 wrote:
On Sun, Feb 16, 2020 at 12:22 AM Dick Arnold <darno...@gmail.com> wrote:
I have a personnel database which has to be edited to keep it current.
I have created search parameters to find the person to edit.
The exact name of the person is not always known, therefore the name field for searching can contain only a few of the characters.  This can create a list of several people.
After the search parameters are entered a "Search" button is clicked and the output, if any, is displayed in a table.
If the search parameters need to be improved, I want the original (current) search argument to be retained in the argument field so I do not need to re-type ALL the search parameters, just the ones I want to change.

I have not been able to find a way to retain the value in the search input box,

Does anyone know how to accomplish this?

Here's the input for one of the input boxes.

<input type="text" id="name_id" name="name_id" placeholder="Enter a few characters">

Set an attribute of value in your input tags, and use the form object in your view to populate it. For reference https://stackoverflow.com/questions/4880306/django-multiple-forms-and-keep-field-data-input-after-submission?rq=1 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages