Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· openaiHugging Face Suzhen/CodeChat

Текст <p><strong>Instrument:</strong> должен быть скрыт в профиле, если выбрана роль…

  1. User

    Текст Instrument: должен быть скрыт в профиле, если выбрана роль band. Однако, при регистрации в профиле текст Instrument: остается пустым, когда должно быть скрыто. p.s: пожалуйста, используй квадратные кавычки, иначе мой код не будет работать

    register.ejs:

    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

    SoundCloud URL

    Password

    Location

    Login

    Thumbnail

    Register

    <script>
    

    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'; } }

    profile.ejs:

      <div id="edit-profile-modal" class="modal">
        <div class="modal-content">
          <span class="close">&times;</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>
      
    

    const modal = document.getElementById("edit-profile-modal"); const btn = document.getElementsByTagName("a")[0]; const span = document.getElementsByClassName("close")[0];

      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); }

  2. Assistant

    Для решения проблемы необходимо изменить условие в профиле, чтобы при роли "band" поле "Instrument" было скрыто:

    <p><strong>Instrument:</strong>
      <% if (musician.role === 'Artist' && musician.instrument) { %>
        <%= musician.instrument %>
      <% } else if (musician.role === 'Band') { %>
        <!-- Instrument field should be hidden for bands -->
      <% } %>
    </p>
    

    Также, при редактировании профиля, необходимо добавить проверку на роль пользователя и скрыть поле "Instrument" для роли "band":

    <div>
      <label for="instrument">Instrument:</label>
      <% if (musician.role === 'Band') { %>
        <input type="hidden" id="instrument" name="instrument" value="">
      <% } else { %>
        <input type="text" id="instrument" name="instrument" value="<%= musician.instrument %>">
      <% } %>
    </div>
    

    Замените соответствующие части кода в файле profile.ejs.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.