Instrument: должен быть скрыт в профиле, если выбрана роль… · The Chat Archive
Explore / Programming Instrument: должен быть скрыт в профиле, если выбрана роль band. Однако, при регистрации… Save Share Download ▾ ReportInstrument: должен быть скрыт в профиле, если выбрана роль band. Однако, при регистрации в профиле текст Instrument: остается пустым, когда должно быть скрыто полностью. p.s: пожалуйста, используй квадратные кавычки, иначе мой код не будет работать
profile.ejs:
code Copy code
<div id="edit-profile-modal" class="modal">
<div class="modal-content">
<span class="close">×</span>
<h2>Edit Profile</h2>
<form action="/profile/<%= musician.id %>/edit" method="POST" enctype="multipart/form-data">
<div>
<label for="name">Name:</label>
<input type="text" id="name" name="name" value="<%= musician.name %>">
</div>
<div>
<label for="name">Role:</label>
<input type="role" id="role" name="role" value="<%= musician.role %>">
</div>
<div>
<label for="genre">Genre:</label>
<input type="text" id="genre" name="genre" value="<%= musician.genre %>">
</div>
<div>
<label for="instrument">Instrument:</label>
<input type="text" id="instrument" name="instrument" value="<%= musician.instrument %>">
</div>
<div>
<label for="location">Location:</label>
<input type="text" id="location" name="location" value="<%= musician.location %>">
</div>
<div>
<label for="bio">Bio:</label>
<textarea id="bio" name="bio"><%= musician.bio %></textarea>
</div>
<div>
<label for="soundcloud">Song 1:</label>
<input type="text" id="soundcloud" name="soundcloud" value="<%= musician.soundcloud %>">
</div>
<div>
<label for="soundcloud">Song 2:</label>
<input type="text" id="soundcloud1" name="soundcloud1" value="<%= musician.soundcloud1 %>">
</div>
<div>
<label for="thumbnail">Thumbnail:</label>
<input type="file" id="thumbnail" name="thumbnail">
</div>
<button type="submit">Save</button>
</form>
</div>
</div>
<!--
<div>
<input type="text" name="soundcloud[]" placeholder="Soundcloud track URL">
<button type="button" class="add-music-button">Add Music</button>
</div>
</div>
</div>
<div>
<label for="thumbnail">Thumbnail:</label>
<input type="file" id="thumbnail" name="thumbnail">
</div>
<button type="submit">Save</button>
</form>
</div>
</div> -->
<% } %>
<script>
Show full message · 279 lines Assistant2023-06-08 02:55 UTC Copy response
Измените блок кода в profile.ejs, отвечающий за отображение поля Instrument, следующим образом:
code Copy code
<p><strong>Instrument:</strong>
<% if (musician.role === 'Artist') { %>
<% if (musician.instrument) { %>
<%= musician.instrument %>
<% } else { %>
<!-- show nothing if instrument is not specified -->
<% } %>
<% } else if (musician.role === 'Band') { %>
<!-- hide instrument field for bands -->
<% } %>
</p>
Примечание:
Мы добавили ещё один блок if, который проверяет наличие выбранного инструмента. Если инструмент не указан, то в профиле он просто не отображается.
Мы убрали знак равенства в <% if (musician.role === 'Artist' && musician.instrument) { %>. Теперь проверяется только наличие инструмента, а не его значение.
Copy first prompt
Details
Provider OpenAI
Model provenance As recorded by source dataset
Turns 1 (2 messages)
Language en
Conversation date Jun 8, 2023
Added to archive Nov 16, 2026
ID 01m7h41b2ssz80kf48gbzx8q6jSource & license Imported from WildChat-4.8M (AI2) (source ). Imported records earn no Research Points.
Upstream record: c862a057a3d1ac2c1f8c3810a5b05d94
Zhao et al., WildChat: 1M ChatGPT Interaction Logs in the Wild (ICLR 2024). Contains information from WildChat-4.8M, made available under the ODC Attribution License.
License: ODC-BY-1.0
const modal = document.getElementById("edit-profile-modal");
const btn = document.getElementsByTagName("a")[0];
const span = document.getElementsByClassName("close")[0];
code Copy code
btn.onclick = function() {
modal.style.display = "block";
}
span.onclick = function() {
modal.style.display = "none";
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
//скрыть плеер, если ссылка не внесена
const song1Input = document.getElementById("soundcloud");
const song2Input = document.getElementById("soundcloud1");
const player1 = document.getElementsByTagName('iframe')[0];
const player2 = document.getElementsByTagName('iframe')[1];
let songs = {
song: "",
song1: ""
}
function hidePlayer(player) {
player.src = "";
player.style.display = "none";
}
function updateSongs() {
songs.song = song1Input.value.trim();
songs.song1 = song2Input.value.trim();
}
function updatePlayers() {
if (songs.song !== "") {
player1.src = https://w.soundcloud.com/player/?url=${songs.song}&color=%23ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true&visual=true;
player1.style.display = "block";
} else {
hidePlayer(player1);
}
if (songs.song1 !== "") {
player2.src = https://w.soundcloud.com/player/?url=${songs.song1}&color=%23ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true&visual=true;
player2.style.display = "block";
} else {
hidePlayer(player2);
}
}
song1Input.addEventListener("input", function() {
updateSongs();
updatePlayers();
});
song2Input.addEventListener("input", function() {
updateSongs();
updatePlayers();
});
updateSongs();
updatePlayers();
//Валидация ссылок с soundcloud
function updatePlayers() {
if (isValidSoundcloudUrl(songs.song)) {
player1.src = https://w.soundcloud.com/player/?url=${songs.song}&color=%23ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true&visual=true;
player1.style.display = "block";
} else {
hidePlayer(player1);
}
if (isValidSoundcloudUrl(songs.song1)) {
player2.src = https://w.soundcloud.com/player/?url=${songs.song1}&color=%23ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true&visual=true;
player2.style.display = "block";
} else {
hidePlayer(player2);
}
}
function isValidSoundcloudUrl(url) {
const regex = /^https?://(soundcloud.com|snd.sc)/(.*)$/;
return regex.test(url);
}
Role
Select a role
A band
Artist
Genre
Select a genre
Rock
Pop
Hip hop
Electronic
Instrument
Select a instrument
Bass
Rythm guitar
Lead guitar
Vocal
function showInstrument(role) {
if (role === 'Artist') {
document.querySelector('#instrument-label').style.display = 'block';
document.querySelector('#instrument').style.display = 'block';
} else {
document.querySelector('#instrument-label').style.display = 'none';
document.querySelector('#instrument').style.display = 'none';
}
}
Copy first response
Not yet included in a published release.