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

254
Views
How to dynamically create an expression using javascript and alpine.js

I'm trying to create a conditional menu in a datatable. For some records the menu will appear, in other cases it will not. My backend (PHP) sends the following parameters to the frontend:

['field' => 'blocked_at', 'operator' => '!==', 'value' => null]

or

['field' => 'blocked_at', 'operator' => '===', 'value' => null]

So in HTML I call the function

<template x-if="checkConditions(record[action.conditions.field], action.conditions.operator, action.conditions.value)">
 <a href="#!" class="dropdown-item" x-on:click="runAction(action, record[action.keyfield])">
  <i x-bind:class="action.icon"></i><span x-text="action.label"></span>
 </a>
</template>

function in Alpine.js

checkConditions (field, operator, value) {
 let condition = `${field} ${operator} ${value} ? true : false`;
 return eval(condition);
},

But it doesn't work, I'm getting the error "identifier starts immediately after numeric literal". I don't know why this happens. There is an error in the checkConditions function.

Could you help me solve this challenge?

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!