Skip to content

Commit

Permalink
add blank default option
Browse files Browse the repository at this point in the history
  • Loading branch information
picklejason committed Dec 18, 2022
1 parent c86ec0a commit df1df58
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
7 changes: 1 addition & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,8 @@ app.get("/", async (req, res) => {

app.get("/create", async (req, res) => {
try {
pick = `<select name=pokemons id=pokemons required>`;
pokemons = await getAllPokemons();
pokemons.results.forEach((pokemon) => {
pick += `<option value="${pokemon.name}">${pokemon.name}</option>`;
});
pick += `</select>`;
res.render("create", { pick: pick });
res.render("create", { pokemons });
} catch (err) {
console.error(err);
}
Expand Down
9 changes: 8 additions & 1 deletion views/create.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@
/>
<label for="pokemon"><strong>Pick your Pokémons</strong></label>
<br />
<%- pick %> <%- pick %> <%- pick %> <%- pick %> <%- pick %> <%- pick %>
<% for (let i = 0; i < 6; i++) { %>
<select name="pokemons" id="pokemons" required>
<option value="" disabled selected>Select a Pokémon</option>
<% pokemons.results.forEach((pokemon) => { %>
<option value="<%= pokemon.name %>"><%= pokemon.name %></option>
<% }); %>
</select>
<% } %>
<br />
<input class="select-text" type="submit" />
</form>
Expand Down

0 comments on commit df1df58

Please sign in to comment.