Closed the1gofer closed 9 months ago
What version of modal forms are you using? the get method was introduced in 1.31 I tested your form and code and it works fine
1.29
Ok, works after updating.
for multi select, are their any methods to get just the text, or individual results? for example result.get("defendants")[0] or result.get("defendants").text. something like that.
The get method takes an optional mapping function you can use to modify the values. So, if you have your values "nested" in an object, you can do something like this.
Imagine this is just a single value but want the text property:
result.get('something', (thing) => thing.text)
If you have several objects and want to join them
result.get('something', (thing) => thing.join(', ')
If you want to join and transform them at the same time, you can do this:
result.get('somethings', (things) => thing.map((i) => `[[${i}]]`).join(', '))
so
let caseName = result.get('case-link')
works, and gives a result like '["something"]'
however
let caseName = result.get('case-link', (thing) => thing.text)
gives a result of "undefined"
ok so it looks like the problem is .text
so
let caseName = result.get('case-link', (thing) => thing)
has the desired result
That is correct. The mapping/transform function is optional,in case you don't provide it what you get back is just the value. On top of that, the mapping function is only called if the value exists, and it will get the plain value, nothing wrapping it.
I'm working in a more advanced and convenient API ,you can take a look at the documentation in the PR if you have to see a preview of how it will work: #178
I see how my first comment could lead to confusion. There is no situation right now where you will get an object with a text value, so my first example was a bit confusing. For completeness , you can also call it with just the key name you want
result.get('something')
Or a more logical transformation could be
result.get('something', (it) => it.toUpperCase())
Templater throws the following error:
To Reproduce
Expected behavior assign value of defendants to variable
Additional context It might be something I'm doing, but I don't see it.