Skip to content

Commit

Permalink
Added auto populate dropdown in patron update
Browse files Browse the repository at this point in the history
  • Loading branch information
allisonglittle committed Dec 4, 2021
1 parent b822280 commit c6b2579
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion library-express/patrons.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ module.exports = function () {
router.get('/:id', function (req, res) {
callbackCount = 0;
var context = {};
context.jsscripts = ["selectTitle.js"];
var mysql = req.app.get('mysql');
getPatron(res, mysql, context, req.params.id, complete);
getTitles(res, mysql, context, complete);
function complete() {
callbackCount++;
if (callbackCount >= 2) {
console.log(context);
res.render('update_patrons', context);
}

Expand Down
3 changes: 0 additions & 3 deletions library-express/public/js/selectTitle.js

This file was deleted.

8 changes: 4 additions & 4 deletions library-express/views/update_patrons.handlebars
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<main>
<script src="https://code.jquery.com/jquery-3.5.1.js"
integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script>
<h1>Update Patron</h1>
<form id="updatePatron" action="/patrons/{{patron.id}}" method="post">
<p><label for="firstName">First Name:</label><br>
Expand All @@ -17,16 +19,14 @@
<input type="tel" name="contactPhone" value="{{patron.contactPhone}}">
</p>
<p><label for="favoriteTitle">Favorite Book:</label><br>
<select name="favoriteTitle" id="title_selector" value="{{patron.favoriteTitle}}">
<select name="favoriteTitle" id="title-selector" >
{{#each titles}}
<option value="{{ISBN}}">{{ISBN}} - {{bookTitle}}</option>
<option value="{{this.ISBN}}">{{this.ISBN}} - {{this.bookTitle}}</option>
{{/each}}
</select>
</p>
<p><input type="submit" value="Submit"></p>
</form>
{{!--
<script src="/public/js/selectTitle.js"></script> --}}
<script>
function selectTitle(ISBN) {
$("#title-selector").val(ISBN);
Expand Down

0 comments on commit c6b2579

Please sign in to comment.