Selected value is not highlighted.
Selected value is not highlighted.
When I edit a record the select field selected value is not highlighted. The options populate fine. I can select an option and save. Record is written correctly to DB and JSON returned(see below) successfully.
I understand for this to work the data table must match the editor field. I have attempted to do that(see below) without success. Please advise what I'm doing wrong.
Editor Field
{
label: 'Email Campaign:',
name: 'prospect.emailcampaign',
type: 'datatable',
optionsPair: {
label: 'name',
value: 'id'
},
config: {
columns: [
{
title: 'Name',
data: 'name'
}
]
}
}
Data Table Column
{ data: 'emailcampaign.name', editField: 'prospect.emailcampaign' },
Returned JSON payload on Edit
{
"data": [
{
"id": "f69a45aa-ebcb-4094-bebc-f59ffad47ee7",
"prospect": {
"linkedin": "https://www.linkedin.com/in/xxxxxxxxxxxxxxxxxxx2268/",
"email": "hello@xxxxxxxxxxxxxxpert",
"lastname": "Marunda",
"industry": "Information Communication Technology",
"city": "Harare",
"title": "Mr.",
"region": "Mashonaland",
"firstname": "Arnold Tonderai",
"avatar": "https:/xxxxxxxxxxxx/4c69647b096b7d00f350ec2b054e8082/290900378/profile.jpeg?s=",
"mobiletelephone": "xxxxxxxxxxx",
"website": "https://arnoldxxxxxxxxxxxxxxpert",
"fixedtelephone": "",
"jobtitle": "Workflow Automation Expert",
"country": "Zimbabwe",
"company": "Edenpoint Projects"
},
"emailcampaign": {
"name": null,
"id": null
},
"socialcampaign": {
"name": "No Footprint-S2C7-Linkedin",
"id": "07e6c08a-e052-486c-b049-6189dbf3d13a"
}
}
],
"options": {
"prospect.emailcampaign": [
{
"name": "Footprint-S1C7",
"id": "758a4c1f-4630-4a09-9234-0f7a4f3c10ea"
},
{
"name": "Non-Footprint-S2C7",
"id": "a3fca475-0677-474a-ad65-46ae5408afd1"
}
],
"prospect.socialcampaign": [
{
"name": "Footprint-S1C7-Linkedin",
"id": "34b4d4ce-4f60-403c-a401-c834592e79ee"
},
{
"name": "No Footprint-S2C7-Linkedin",
"id": "07e6c08a-e052-486c-b049-6189dbf3d13a"
}
]
},
"files": []
}
Screenshot of issue
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This question has an accepted answers - jump to answer
Answers
Hi,
The way Editor is set up there is that it is being told to look for data in
prospect.emailcampaign
. However, there isn't aemailcampaign
field in theprospect
object. There is aemailcampaign.id
, but I'd be surprised if you wanted to edit that!Can you show me your controller code - specifically I'm looking for information about the join that is used to tell the
prospect
row, what email or social campaign it should link to. Is that a column in theprospect
table?Allan
Hi Allan,
My controller code is in Python on the Anvil.works runtime server as follows...
Build JSON payload to be returned to Editor
Update Prospect row with formdata paramatersfrom Editor
Apologies, I'm not a Python developer. I presume this has an SQL backend - so perhaps we can discuss in those terms. What links a
prospect
to an email campaign? Is there anemail_campaign
column in the prospects table?Allan
Yes,
email_campaign
andsocial_campaign
are fields in the SQL DB with a one-to-one join relationship with respective tables.Not quite following your investigation into the data model. I thought Editor would just use the JSON file presented to it?
Okay, so there is a
email_campaign
column in theprospect
table? And that in turns holds an id that relates toemailcampaign.id
?That being the case, I would expect to see a
email_campaign
value in theprospect
object, since that is the value that you want to edit to update the reference. You wantemailcampaign.name
to display in the DataTable, that's fine, but when you actually update the record to point at a different email campaign then you need to change the value ofprospect.email_campaign
.If you look at this example you'll see that there is a
users.site
value, which points to the id in thesites
table. I usesites.name
to display in the DataTable, but when a user's site changes, it writes the site id tousers.site
.Allan
Hi Allan,
Thank you for looking at this in detail. Much appreciated.
Have followed your instruction and it works. The example was very useful.
regards,
Arnold
Awesome - great to hear you've got it working
Allan