-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial action of Datasource and custom code #380
Comments
Hi, @nimaforoughi |
thank you Vit, I have written the below code to read the response from postgres Datasource and parses the id and values then put it the payload. my payload finally will be like an object with key and values. the elements in the panel are multi select. Can you please assist to diagnose it.
|
Hi, @nimaforoughi and Custom Code After that my form elements highlights in red color, which shows that the value of the element is different from the initialial value when I click on submit button I see my initial values But I believe your goal is to set values for the elements Put some code for initial code and use onChangeElements. onChangeElements - set up values on elements. const contextElements = context.panel.elements
if (context.panel.response) {
const frame = context.panel.response
.data.results.A.frames[0]
// map values from response
const framevalues = frame.schema.fields.map((value, index) => ({
field: value.name,
value: frame.data.values[index]
}))
// new Elements with values
const newElements = contextElements.map(element => {
const frameElement = framevalues.find(frElem => frElem.field === element.id)
return ({
...element,
value: frameElement.value[0]
})
})
console.log('newElements ', newElements)
// use onChangeElements
context.panel.onChangeElements(newElements)
} |
Hello,
Is there any sample code for initial ‘custom code’ section to read data from Postgres db table(the payload is taken from ‘initial Request Payload) and update the panel elements values accordingly?
Your configuration.sql example would be my preference.
The documentations only have custom code for ‘Query’ as the initial acton and nothing for ‘Datasource’
regards
Nima
The text was updated successfully, but these errors were encountered: