Am I misunderstanding? Server Connect 'Values' formatter

When I use the ‘.values()’ formatter server-side (PHP), I thought it would take a parameter to return the values of a given object property (like it does client-side). The data picker doesn’t have a parameter option.

What does ‘values’ do server-side then?

What I want to do is use ids from the result of a query to be an ‘in’ parameter for another query. How would I do this?

This might help:

array_result.groupBy('id').keys()
2 Likes

You, my friend, are a legend! Thank you

The question still exists, what is .values() for?

Can’t say I’ve ever used it, but the code is simple enough:

if (typeof obj != 'object') return obj;
        return Object.values(obj);

So if you pass it an object, it returns the values of that object. Haven’t come up with a use case myself.

1 Like

Looking at the formatters code (which I’m embarrassed to say I should have looked at first!), it looks like the .unique() option would fit too without having to use two formatters.

function formatter_unique($val, $prop = NULL) {
    if (!is_array($val)) return array($val);
    return array_unique($prop != NULL ? array_column($val, strval($prop)) : $val);
}

As long as you’re happy not having duplicates, which for an ‘IN’ condition makes sense, it seems to do the job. I think having a similar formatter (built in to the Wappler UI rather than custom) that worked the same as unique() but returned all values, would be a good addition.

1 Like

Values and keys mimic the same operations as on JavaScript objects.

Keys gets an array with all the key names of an object and values gives an array of all the key values

1 Like

Some examples from my code, good luck working them out! :smile:

specialist_data.data.values(`sd_value == 0 ? '' : sd_id + '_' + sd_value`).contains(add_costs_id + '_' + add_costs_fig)

specialist_data.data.values(`sd_id == add_costs_id ? sd_value : 0`).max() > 0
1 Like

Can we get a separate formatter that acts like .unique() (draws all the values for a specific property of an object) but doesn’t filter to unique?

1 Like