Search code examples
expressejsexpress-validator

EJS syntax error while compiling ejs code in Create Form


I have a syntax error when I try to render this part of my template with EJS (on a node server).::

enter image description here

I'm trying to show a view of a create form, so when the user leaves a blank input or doesn't select the dropdown option gets an error (using express validator). I works fine with an input, validates an error and keeps the data of all other inputs (so user won't have to retype all over again)

But when using the option select, it's getting an error. Also the data should persist in the option select IF it's in blank or error in any other fields.

I'm quite sure the error is here:

    <label class="combo-form_titles_create" for="os_min">OS Minimum Requirement</label>
        <select 
          name="os_min" 
          class="textArea__Create <%= locals.errors && errors.os_min ? : null %>">
          <option value="">Choose an Operating System</option>
          <%  
          let systems = ['Windows XP', 'Windows Vista', 'Windows 7', 'Windows 10'];
          %>
          <% for (const oneSystem of systems) { %>
            <option 
              value="<%= oneSystem %>"
              <%= locals.oldData && (oneSystem == oldData.os_min) ? 'selected' : null %> 
            > <%= oneSystem %> </option>
          <% } %>
        </select>
        <% if (locals.errors && errors.os_min) { %>
          <div class="text-danger">
            <%= errors.os_min.msg %>
          </div>
        <% } %>

When using the inputs only there is no error

        <input class="textArea__Create" type="text" name="os_rec" placeholder="OS Recommended Requirement" value="<%= locals.oldData ? locals.oldData.os_rec : null%>"/>
        <% if(locals.errors && errors.os_rec){ %>
          <p class="tableAdmin_Error"><%= errors.os_rec.msg  %>  </p>
        <% } %>

Solution

  • found it, it's in the line 4

    class="textArea__Create <%= locals.errors && errors.os_min ? : null %>">
    

    in the ternary operator Im not passing anything if true