question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

concept issue: defining functions for field properties

See original GitHub issue

Great stuff!

However there seems to be an issue with the concept of defining functions for fields properties and validators as standard JSON does not allow / support to generate JSON containing javascript functions like the following:

{
  type: "select",
  label: "Type",
  model: "type",
  values: [
    { id: "personal", name: "Personal" },
    { id: "business", name: "Business" }
   ]
},{
  type: "text",
  label: "Company name",
  model: "company.name",
  visible: function(model) {
    return model && model.type == "business";
  }
}

The workaround from #149 does not work in version 3.

Is there any know way to solve this??

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
DelfsEngineeringcommented, Mar 26, 2019

I also handled this in a similar fashion. Although a bit more work but very flexible. I have a parser that finds any key with the _calc extension and converts the value to an evaluated function and added as a getter. This way it works with all keys anywhere in the schema.

eg

visible_calc = "model.sAllowed"
// or 
values_calc = "model.myArrayOfValues"
// or 
styleClasses_calc = "model.isOverdue ? 'warning' : 'information' "

My technique replaces the raw key with the getter function

1reaction
zoul0813commented, May 29, 2019

I’m not a big fan of evaluating a function like that… what I did was created the functions in my code, and just passed Paramus to them from the Json schema.

A quick look … seems your code should work though. I haven’t touched VFG in a few months though, so don’t have a project handy to test on at the moment (switched jobs back in March).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Function Fields - TechDocs
Function fields are special types of fields that you can use in device designs and action diagrams. The attributes of a function field...
Read more >
Introduction to data types and field properties - Microsoft Support
Every table in Access is made up of fields. The properties of a field describe the characteristics and behavior of data added to...
Read more >
Function field - Product Documentation | ServiceNow
Create function fields and scripts in the Now Platform to perform common database transformations and calculations.
Read more >
Field (mathematics) - Wikipedia
In mathematics, a field is a set on which addition, subtraction, multiplication, and division are defined and behave as the corresponding ... Function...
Read more >
Method definitions - JavaScript - MDN Web Docs
Method definition is a shorter syntax for defining a function property in an object initializer. It can also be used in classes.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found