Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

256
Views
¿Cómo crear correctamente una declaración If/Else usando Handlebars.JS?

Tengo un botón que, dependiendo de si la entrada de texto que activa está abierta o no, cambia entre 'Informar un problema' y 'Cerrar'. En un esfuerzo por consolidar mi código, decidí usar Handlebars.JS para crear lo siguiente:

 <button id="myBtnToReportABug" onclick="toggleReportForm(); clearFields();" type="button" class="btn btn-secondary float-right" >{{#if report_form_opened}} Report A Problem {{else}} Close {{/if}}</button>

He seguido los ejemplos en la documentación y, como puede ver en el Javascript que adjuntaré a continuación, tengo un interruptor en funcionamiento en togggleReportForm, cuya consola registra verdadero y falso con cada clic. No estoy seguro de lo que me estoy perdiendo aquí y agradecería cualquier consejo.

Actualmente, el botón solo muestra 'Cerrar' sin mensajes de error.

 var report_form_opened = report_form_opened; $(document).ready(function() { const client = ZAFClient.init(); $("#myBtnToReportABug").click(() => collapse.collapse('toggle')); $("#bugForm").submit((e) => { e.preventDefault() const input = document.getElementById('nameInput'); bugInfo = { "name": "Report From " + idTicket, "story_type" : "Bug", "description": input.value + " " + `${data.ticket.brand.url}/agent/tickets/${idTicket}`, } reportBug(bugInfo).then(collapse.collapse('toggle')) }) }); }); }); async function reportBug(data = {}) { const url = 'https://www.pivotaltracker.com/services/v5/projects/2530461/stories' const response = await fetch(url, { method: 'POST', headers: { "X-TrackerToken": `${metadata.settings.token}`, "Content-Type": "application/json" }, body: JSON.stringify(data) }); return response.json(); } // changes text on 'report problem' button when form open function toggleReportForm() { report_form_opened = !report_form_opened; console.log(toggleReportForm) } // clears text field onclick function clearFields() { document.getElementById("nameInput").value = ""; }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!